stm32duino / Arduino_Core_STM32

STM32 core support for Arduino
https://github.com/stm32duino/Arduino_Core_STM32/wiki
Other
2.85k stars 979 forks source link

fix(wire): support only 7 bits addressing mode #2493

Closed fpistm closed 3 months ago

fpistm commented 3 months ago

Arduino does not support 10 bits addressing mode. The API is limited to an uint8_t address: https://github.com/arduino/ArduinoCore-API/blob/4a02bfc0a924e1fec34c3bb82ffd5dfba7643a0c/api/HardwareI2C.h#L31 https://github.com/arduino/ArduinoCore-API/blob/4a02bfc0a924e1fec34c3bb82ffd5dfba7643a0c/api/HardwareI2C.h#L36

About the hack to use 10 bits on Arduino:

Normally on arduino, you can communicate with this device simply by doing something like this:

Wire.begin(0x79);
Wire.write(0x08);
//insert additional communication here
Wire.endTransmission()

However, when using the same code on STM32Duino this communication won't succeed. First of all, 0xF2 (0x79 << 1) byte will appear twice on the bus (because we are configuring HAL's I2C interface in 7bit mode, however the MCU itself recognizes this address as the beginning of 10 bit address).

This is not possible as it is manage by hardware to follow I2C specification where: 11110xxx is reserved for 10-bit Slave Addressing.

Fixes #2468.