I2C Read Bit?

03 Jun 2010

Hi:

In working with the DS2482 I2C to 1-Wire bridge I need to be able to read specific bits from a Status register in the device.  Eventually this is to be used for polling in order to know when I can then issue 1-Wire commands.

The DS2482 defaults the Set Register Pointer to the Status register after each DS2482 level command is issued.

I am writing to the device to issue a reset and then attempting to read the status register.

// Reset DS2482

int Reset_DS2482(int I2C_address, int command)
{
   char cmd[1];
   cmd[0] = 0xF0;
   DS2482.write(I2C_address, cmd, 1);
   char status[1];
   DS2482.read(I2C_address, status, 1);
   return status[0];
}
The value I am getting back is "10007FF0".

from

pc.printf("Status is : %X\n\r", status[0]);
I seem to have to use the cmd[1] and status[1] to treat values as character strings in the read and write commands for I2C.  Why can't I send integers?

I'd like to understand how to test the bits in the status register.

Thanks

Tim

03 Jun 2010

Hi Tim,

10007FF0 smells like the value of a pointer to me (of a local/stack variable in RAM), rather than a variable. Is the code you posted actually that giving you the behaviour you saw?

For example, if you did:

char status[1];
printf("%X\n", status);     // would give the address of status[0], likely around 10007Fxx
printf("%X\n", status[0]);  // value of status[0], which must be a value 00-FF
So i'd check that you are not looking at the pointer, rather than the value it points to.

Simon

03 Jun 2010

Hi Simon:

Thanks for explaining that.  It would be the address as you have noted.

What about specifying individual bits within Status[0]?  How do I get to that level of detail?

Thanks

Tim