I2C Problem on R4 wifi

Problem solved!

The initial advice was spot on. Originally I tried both the suggested alternative reads but nothing worked. Then in the early hours I had a light bulb moment. This morning I tried again but changed the declaration of the receptor variable from uint16_t to short. Everything then worked.

In summary . . . . .

aX = Wire.read() << 8 | Wire.read();
works on an R3 but does not work on a R4

short bh = Wire.read() << 8; bh |= Wire.read(); aX = bh;
works on both R3 and R4.

Many, many thanks to all who chipped in with advice. I would never have found it without that help.

2 Likes

Any technical analysis why the data type does matter?

Possibly, it's due to non-zero bits being shifted into the variable under certain conditions. Or a newly initialized variable contains non-zero data. Either of these I'd put my money on. It would be simple enough to test which it is, although if this were my project, I'd probably be happy enough that it works and move on.

Indeed that is the case. I assumed the difference would be due to signed vs unsigned in that variable.