That what I did,
but in the FEZ spider there are 4 socket with the letter "I’,
so i connect it for example to socket no. 3,
but in the ctor of the, or the execute function of I2CDevice there is no parameter of socket number or pins?
void ProgramStarted()
{
var switchUsbSocket = Socket.GetSocket(3, true, null, null);
//where can I configure with this variable?
var I2CConfig = new I2CDevice.Configuration(0x7f, 1000);
var I2C = new I2CDevice(I2CConfig);
try
{
byte[] b = new byte[2];
var xActions = new I2CDevice.I2CTransaction[2];
xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0x00, 0x00 });
xActions[1] = I2CDevice.CreateReadTransaction(b);
I2C.Execute(xActions, 1000);
}
catch (Exception x)
{
throw new Exception(“exception thrown.”, x);
}
}
OK, so some of your questions are not really relevant so I’ll try to help out on some of the underlying concepts.
I2C is a bus. So the pins exposed on each socket are the same physical pins… plugging a device into one socket should be no different to plugging it into any other socket. (and to verify the pinout, you can look at the Spider schematic PDF and see that they are all using IO11 and IO12)
In a Gadgeteer sense, Gadgeteer extends the logical (software) I2C bus design away from what the core netmf definition is, so in the ctor of the GTI I2C bus they use the socket - for example, the Seeed Gyro module is an I socket device, check out this source code:
I don’t sure myself about read and write,
when reading- I have to create before write transaction for bring the address?
I have to bting the address with the r/w bit, I mean: when I create read transaction, to address 0x00:[0x01]-for the right bit is the r\w bit? ot the I2C interface create it itself?
I think I’l understand it clearly if you can bribg here an simple example of write to 0x05h address, and read from this address to check.
Hi, Chaya. You can use the I2CDevice.WriteRead() method to read the value stored in a specific register address. You can take a look at the I2C transactions in my codeshare entry for an example: https://www.ghielectronics.com/community/codeshare/entry/772
Check out the VideoOutModulePlainNETMF.Program.VideoOutConfigVGA800x600() method. There are plenty of write transactions followed by a write/read from a specific register at the end of the method. I use SoftwareI2C to allow me to use any digital I/O as I2C pins instead of the dedicated hardware ones.
so I changed the code to:
void ProgramStarted()
{
var switchUsbSocket = Socket.GetSocket(3, true, null, null);
var i2c = new GTI.I2CBus(switchUsbSocket, 0x50, 100, null);
byte[] b = new byte[1];
int i = i2c.WriteRead(new byte[] {0x00}, b, 1000);
Debug.Print(b[0].ToString() + i);
}
but after runing- both b and i equals 0,
what should be the issue now?
void ProgramStarted()
{
var switchUsbSocket = Socket.GetSocket(3, true, null, null);
var i2c = new GTI.I2CBus(switchUsbSocket, 0x50, 100, null);
byte[] b = new byte[1];
int i = i2c.WriteRead(new byte[] {0x00}, b, 1000);
Debug.Print(b[0].ToString() + i);
}
What Architect is pointing out is that 100% of faults like this with I2C devices comes down to using the incorrect address. NetMF uses the 7-bit address, not a modified 8-bit read/write address, so for your device you will get 0xA0 and 0xA1 as the read/write addresses pushed to the wire because you’ve used the address of 0x50. If you need 0x50 and 0x51 on the wire, then the correct address for the device in question is 0x28.
If you are connecting to A17 and B19 then this is not an I2C bus slave. It is only I2C when enabled for the external EEPROM and the device is the master.
When enable as a slave, it is in SMBus mode and although this is similar to I2C, the command structure is different and I am not sure that the NETMF implementation will work with this. I’ll wait and see if anyone else has used it for SMBus before?
I don’t know about the SMBus,
but the default configuration,
and that is what in my device as I checked,
it is configure to I2C mode (it is changing bottun for SMBus mode…)
When you configure it for I2C using SMBUSz pin, the device will expect that there is an external I2C EEPROM chip is connected and the device will try to read the configuration from it.