Quick note, for those who might be banging their head, like I did.
ST HAL library 7 bit I2C address has to be shifted before passed to their functions.
EDIT: Let me google that for you situation. I’ve been working with the official ST documentation, when I just had to google to find this beautiful blog post from 2 years ago.
Using the simplest API call to send something to device
/**ST HAL handler, address, data, size, timeout*/ HAL_I2C_Master_Transmit(hi2c, 0x3E, buffer, bufferSize, timeout);
And plugging a Saleae logic analyzer, I get:
Surprise, Surprise Mother******,
0x1F for you.
This has a simple explanation that escapes my comprehension. The API writes directly to I2C CR2 register (check the reference manual for your ST µC) without shifting. Isn’t the goal of an API to be clear and easy?. This is not stated anywhere and I lost a good amount of time tracking this problem.
My quick solution:
#define I2C_ADDRESS_ST(a,m) (((m) == I2C_ADDRESSINGMODE_7BIT) ? (a << 1) : (a))
Hope that if this happens to you, you find this post, or Jures’ one before wasting too much time.