I2C

Post Reply
edringel
Posts: 7
Joined: Wed Jun 08, 2011 4:02 pm

I2C

Post by edringel » Thu Aug 11, 2016 3:43 pm

Hi,
Trying to understand why an i2c sketch doesn't work on a fubarino sd. Before I start really digging and debugging, there seems to be an obvious question.
The board literature indicates that there are two i2c channels.
Do I need to specify which channel? If so, how? Do I need to modify any of the Wire documents to do so?
Thank you.

Ed

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: I2C

Post by majenko » Thu Aug 11, 2016 7:25 pm

The Wire.h library only supports one (the primary) I2C channel. To use the other channel you should port your code to the DTWI library which supports both channels but has a different API.

The primary channel uses pins 1 and 2 (SDA/SCL respectively).

Don't forget (something which many Arduino users don't realise) you need 3.3KΩ pullup (to 3.3V) resistors on both the SDA and SCL lines. The Arduino boards wrongly enable the internal pullups which are completely the wrong value for an I2C bus (typically 10-20x too big).
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

edringel
Posts: 7
Joined: Wed Jun 08, 2011 4:02 pm

Re: I2C

Post by edringel » Thu Aug 11, 2016 7:52 pm

Thanks.
I do have pullup resistors, and I am using pins 1 & 2. Guess I need to do a bit more digging.
Thank you.

Ed

GastonLagaffe
Posts: 101
Joined: Sun Oct 26, 2014 2:50 pm

Re: I2C

Post by GastonLagaffe » Fri Aug 12, 2016 8:55 am

Salut,

I looked at the DTWI native code and what wire does. As Matt stated, wire is simply a wrapper around the DTWI library and after some tests it appears to me that whatever I tried I ended up writing the same wrapper in my local code. So I finally decided to modify the wire library and rename all to wire2 for the second bus. I have the lib attached if you want to take a look at it. With that lib I was able to drive a I2C OLED on the second bus.

With wire2, all you have to do is replace all wire statements in the sketch with wire2

Ciao, Mathias
Attachments
Wire2.zip
(5.4 KiB) Downloaded 35 times

Post Reply