Go Down

Topic: I2C sample code rewriting in Wire (Read 1 time) previous topic - next topic


Unfortunately the code does not work. There's always a "0" returning.

Which one? Mine? That wasn't intended to work, it was just an example. For example the address was just a random number. You have to modify or at least provide a link to the datasheet of your device, so we have a chance to get the necessary information.

Where do I have to write the control bytes?

The control bytes are the address plus read/write bit, so they are in the code already.

And how can a repeated start be done?

Does that mean a start condition without a stop condition? Else you have to define it.


Now it works. I didn't know that read/write bits are set by the library. Another problem was the endTransmission. In Arduino v1.0.1 this method can be called with the false flag. So no stop condition is sent.

Device address is 0x44.

Code: [Select]
byte get_register(byte memory_address) {
  Wire.requestFrom(DEVICE_ADDRESS, 1);
  if (Wire.available() > 0) {
    return Wire.read();
  return 0;

Thanks again for your help.

Go Up