11 years, 6 months ago.

i2c.read == first adres of the slave or immediatly value?

When we want to read a register from a slave we do:

int readRegister(int addr, char address)    
{                                                               
  char data=0;   //in code unsigned
  i2c.write(addr, &address, 1, 1);
  i2c.read(addr, &data, 1, 0);
  return (int)data; 
}

When looking whats happening on the bus: First we send the addr of the slave MSB first, then we send the register. Repeated start condition. But then...

-again first sending the adres of the slave and the slave will put the value of that register on the bus

-the slave immediatly put the value of that register on the bus

thnx

1 Answer

11 years, 6 months ago.

It will (and needs to) first send the address of the slave + that it wants to read from the slave (the LSB address bit determines that). So your first option is the correct one.

Accepted Answer