I’m not getting response from my i2C device (Execute return 0), the device address is correct (0x40) according to the specification.
Am I connecting it wrong or the i2C device / GH120 module is faulty?
Sample code from GHI website:
I2CDevice.Configuration con = new I2CDevice.Configuration(0x40, 100);
I2CDevice MyI2C = new I2CDevice(con);
// Create transactions
I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[2];
// create write buffer
byte[] RegisterNum = new byte[1] { 2 };
xActions[0] = I2CDevice.CreateWriteTransaction(RegisterNum);
// create read buffer to read the register
byte[] RegisterValue = new byte[1];
xActions[1] = I2CDevice.CreateReadTransaction(RegisterValue);
// Now we access the I2C bus using a timeout of one second
// if the execute command returns zero, the transaction failed (this
// is a good check to make sure that you are communicating with the device correctly
// and don't have a wiring issue or other problem with the I2C device)
if (MyI2C.Execute(xActions, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
else
{
Debug.Print("Register value: " + RegisterValue[0].ToString());
}
@ EvoMotors - Are the A0 to A5 signals tied to ground (Low), this will place the slave device address at 0x40 to match your code. Next issue is accessing the register at address 02h will not respond to a read request right after power up, see page 26 of the datasheet for details on programming the Subx bits in the Mode 1 register first.
If you just want to test the I2C connection to the PCA9685 try reading back register at offset 00h instead, that should at least respond with an Ack.
I didn’t see any register that would response with a known value, so that the best I can find for you right now.
I was initially betting on a I2C 7-bit vs 8-bit address issue, but it actually looks like it could be ok givenm the way the Adafriu. Having said that, perhaps try with 0x20 as the address and see if that changes the behaviour
I started playing with this device about a year ago and looking back at the code I was using the address 0x40. I seem to remember that there was something odd about the supply connections to the module. I can’t remember exactly but think that supply had to be connected to the two screw terminals and not the edge connector. I’ll try finding the module over the weekend and try again.
I agree, that’s what they document there. And they document 0x40 in the tutorials and their code. But by looking at the NXP datasheet, Figure 4, you can see the 7-bit address should be 0x40. If you have pull-up on any of the address lines then this changes, but the default address should be 0x40.
The thing to watch here is the 7 bit address is what the documents state, on the wire or by the time the PCA9685 sees the byte value, the 7 bit address has been shifted left one position. So a 0x40 becomes 0x80. Bit 0 becomes the read / write signal to the device. The bits 6 to 1 in between are the address bit strapping A5 to A0.
It doesn’t really make much difference here unless you’re sniffing with a logic analyser.
The important thing to note: for NETMF, you must only use the 7-bit address in the I2C constructor. Doing anything else will not work (the wrong bit pattern will get sent on the wire) as NETMF will automatically deal with the R/W bit, bit 8, and shift the 7-bit address appropriately.
@ EvoMotors - As @ Brent mentioned the I2C constructor takes a 7 bit address, and my comment is that 0x80 is not a valid 7 bit address. Only the bits on the wire matter to the PCA9685 which is all it can possibly care about, not the constructor format.
@ scardinale - Just tried the scanner code. So may be problem in the connection. It runs through the code and always returns 0. What am I missing in the connection?
@ EvoMotors - In your original sample did you change the value for RegisterNum from 2 to 0 and try that?
You haven’t described how you powered the PCA9685, board or the state of the A0 to A5 jumpers, It will be harder and harder to assist you with out the details requested.
There are 2 power pins that I can see. V+ for the servos which can be 5V and VCC for the logic which must be 3.3V for the G120. Make sure your ground is common to this board and your G120TH otherwise it won’t work. Leave the OE disconnected as it defaults to GND.