I2C difficulties with DS75

Hi,

I am trying to communicate between a FEZmini and DS75 I2C temperature sensor.
Here is part of the program. It is a thread that interrogates the DS75. I always get the following error :

Exception System.ArgumentException - 0xfd000000 (5)

Microsoft.SPOT.Hardware.I2CDevice::Execute [IP: 0000]

MicroFrameworkTest01.Program::Thread03 [IP: 0047]

A first chance exception of type ‘System.ArgumentException’ occurred in Microsoft.SPOT.Hardware.dll
We got exceptionSystem.ArgumentException

What could be the problem? The software seems OK.

public static void Thread03()
{
//create I2C object
I2CDevice.Configuration con = new I2CDevice.Configuration(0x9F, 400);
I2CDevice MyI2C = new I2CDevice(con);
//create transactions (we need 2 in this example)
I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[3];
// create write buffer (we need one byte)
byte[] RegisterNum = new byte[1] {0};
xActions[0] = MyI2C.CreateWriteTransaction(RegisterNum);
// create read buffer to read the register
byte[] RegisterValue = new byte[2];
xActions[1] = MyI2C.CreateReadTransaction(RegisterValue);
while (true)
{
// Now we access the I2C bus and timeout in one second if no responce
try
{
MyI2C.Execute(xActions, 5000);
}
catch (Exception e)
{
Debug.Print(“We got exception” + e.ToString());
}
Debug.Print("Register value: " + RegisterValue[0].ToString() + RegisterValue[1].ToString() );
}

Do you have the latest firmware and SDK?

And at what line you see the exception?

Have you tried 0x9F >> 1 for the address? I think NET MF takes 7 bit address.

It’s I2C that takes 7 bit address, the 8th is 0(write) or 1(read).

This is explained in the Beginner’s eBook available on this site :stuck_out_tongue: :wink:

I am using the micro framework 4.0

I get the exception at this line :
MyI2C.Execute(xActions, 5000);

Concerning the Adress the datasheet of the DS75 says
1 0 0 1 A2 A1 A0 R/W => in my case this is 1 0 0 1 1 1 1 1 => 0X9F

The meaning is to write 1 byte and read 2 bytes back.

Besides the problem above all the rest is working perfectly
serial in/out
digital
analog
pwm
rc servomotor

Do I still have to add a pull up resistor to the SDA and SCL line? Or are the ones on the board enough.
I am lost for the moment.

So have you tried Supas’s advice?

Shift the address one bit to the right side

In your case 0x9F >> 1 => 0xCF

Use 0xCF as I2C address. The pull up resistors on the board are enough and should run smoothly.

Nothing is wrong in the line you showed so it is probably something wrong with xActions. Or in the creation of the I2C object.

Make your code as small as you can and post it here.

I have found it :slight_smile:

this
I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[3];

should have been
I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[2];

Thanks for pointing me in the right direction