mongoose-os-libs / i2c

Other
4 stars 6 forks source link

Misleading trace in mgos_i2c_send_byte does not help debugging I2C interface code #1

Closed feeley closed 7 years ago

feeley commented 7 years ago

The log generated by mgos_i2c_send_byte incorrectly states that the byte sent is 0x00 at this line:

https://github.com/mongoose-os-libs/i2c/blob/a94543dcb4fd849e1bd6ed21b081ce29b816d159/src/common_gpio/mgos_i2c_gpio.c#L129

This is because the variable data has been modified by the previous for loop which does data<<=1. A better for loop which does not destroy the content of data is:

  for (i=0x80; i!=0; i>>=1) {
    bit = (data & i) ? 1 : 0;
    ...

A better name for i is probably mask with this new loop.