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.
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 doesdata<<=1
. A better for loop which does not destroy the content ofdata
is:A better name for
i
is probablymask
with this new loop.