Main Site Documentation

2nd I2C on G400D question


#1

Hello!

From the datasheet:

I2C is a two-wire addressable serial interface. The G400 can act as an I2C bus master only with 7-bit slave
addresses. It can connect to one or more slave devices over the same connection with a maximum clock of 400
kHz. The I2C bus interface requires pull up resistors to be added on both the SCL and SDA pins, usually 2.2 kΩ.
It is possible to simulate an independent I2C bus on any two GPIO pins with the appropriate resistors though the
software I2C class, but performance will be lower.

It indicates you can have another independent I2C bus on any two GPIO pins through the I2C class, however, I
don’t see how to designate using the SCL & SDA pins via software.
For example, I have this code:

        I2CDevice.Configuration i2cCfg = new I2CDevice.Configuration(0x6B, 100);
        I2CDevice i2cConnection = new I2CDevice(i2cCfg);
        I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[2];
        byte[] regNum = new byte[1] { 2 };  //write
        byte[] regVal = new byte[1];
        xActions[0] = I2CDevice.CreateWriteTransaction(regNum);
        xActions[1] = I2CDevice.CreateReadTransaction(regVal);
        int i = i2cConnection.Execute(xActions, 1000);

when I read it is always 0, but then again, how would the library know to use PA7 & PA8 instead of PA30, PA31?

I want to create an I2C bus using PA7 as I2C SDA & PA8 as I2C SCL.
I see no way set these gpio as the ones to use for this I2C bus.
The default is PA30 & PA31 which are being used by the touch screen.

I’m sure it is something easy but I don’t seem to be able to figure it out…

thanks for your help.


#2

from the old I2C info page, http://old.ghielectronics.com/docs/12/i2c, you will find this teaser:

Software I2C
When using I2C, it is highly recommended that you use the built-in hardware support for I2C. In some cases though it may be necessary to have another I2C bus or it is necessary to use specific pins that are not I2C pins. In this case, I2C can be handled all in software, though performance will be lower.
The GHI libraries includes a software I2C implementation in the GHI.Hardware assembly (GHI.IO.SoftwareI2CBus).

Go to the SoftwareI2CBus doco http://old.ghielectronics.com/downloads/man/Library_Documentation_v4.3/html/T_GHI_IO_SoftwareI2CBus.htm to see how you can change the code to use Software I2C and set any pins.


#3

But lets also talk concepts of I2C here for a moment. I2C is a bus, you can have multiple items on the bus and it will work. The challenge is your I2C touch code may not be device-safe so you could use another device on the bus, but you certainly could try it!


#4

Just to add one quick thing, the pins used for hardware I2C in NETMF cannot be changed and NETMF only supports one I2C bus. If you need I2C on any other set of pins for whatever reason, software I2C is the way to go.


#5

Thanks Brett & John for the info.

Even though the data sheet says “It is possible to simulate an independent I2C bus on any two GPIO pins with the appropriate resistors though the software I2C class”, I hadn’t made the connection that the software I2C class was
actually a completely different class from the one I was using. I just read that sentence as a general statement.

Anyway, thanks for the help, I will give it a try.