Bug with I2C (panda 2 + cmps10 )

Hi, I have a problem

Exception System.ArgumentException - 0xfd000000 (1)

#### Message: 
#### Microsoft.SPOT.Hardware.I2CDevice::Execute [IP: 0000] ####
#### GHIElectronics.NETMF.FEZ.FEZ_Components+GererI2C::ReadRegister [IP: 0057] ####
#### GHIElectronics.NETMF.FEZ.FEZ_Components+GererI2C::ReadParametres [IP: 0006] ####
#### Robot_tondeuse.Program::Main [IP: 0033] ####

Une exception de première chance de type ‘System.ArgumentException’ s’est produite dans Microsoft.SPOT.Hardware.dll
Une exception non gérée du type ‘System.ArgumentException’ s’est produite dans Microsoft.SPOT.Hardware.dll

Uncaught exception

       public int ReadRegister(byte address) //n register
            transactions = new I2CDevice.I2CTransaction[2];

            byte[] WriteData = new byte[1] { address };
            transactions[0] = I2CDevice.CreateWriteTransaction(WriteData);

            byte[] ReadData = new byte[1];
            transactions[1] = I2CDevice.CreateReadTransaction(ReadData);
            if (i2cBus.Execute(transactions, TRANSACTIONEXECUTETIMEOUT) != 0) <--- :o Boum !!

Hi Claude,

can you tell me why you think this is a bug?

I think we need to see more of your code. We need to know what address you’re using, where you’re creating the I2CDevice.Configuration.

I would also suggest that you take simple steps first - instead of abstracting the read of the register, just write a short sequence of commands that will report back a few of the different registers, like software version and bearing. That way you can prove that you have figured out how I2C works and then how to talk to the device. See the tutorial http://wiki.tinyclr.com/index.php?title=I2C_-_EEPROM for I2C general setup code.

Brett, thanks

The problem is configuration requires a 7-bit address and address of cmp10 is xC0 minimum !!!
What can I do ? Sell CMP10 !! :’(

There’s no problem with 0xC0 address :o

You should initialize your device like this :

ConfigCMPS10 = new I2CDevice.Configuration((ushort)(0xC0 >> 1), 100);

This is an example for a device at address 0xC0 and 100KHz. You may adjust the frequency for your device, though.

0xc0 is the 8 bit address, not the 7-bit address.

Why oh why do vendors still do this :wall: Please folks, get with the program, only talk about 7-bit addresses and use them everywhere !!!

If you search the interwebs for this device, the vendor has talked about the address value http://www.robot-electronics.co.uk/htm/arduino_examples.htm As Bec says, the 8-bit address can be found by shifting one bit, but still I would prefer to talk about the device as having address of 0x60.

It’s OK !!

thanks to you !!

Brett, you’re right about this but I think it’s now an habit, so harder to change :frowning:

Btw, if you see an address greater than 0x7F then you are sure it’s a 8bits address and that it then needs a shift to be used :wink:

Claude, glad it’s working now !