Re: i2c_burst_write API

Piotr Mienkowski

Hi Erwan,

You may have solved your problem already, if not maybe you'll find the
following comment useful.

The proper way to write data to an i2c device with a one byte internal
address (on a bus level) is as follows:

S Addr Wr [A] subAddr [A] Data [A] Data [A] ... [A] Data [A] P


S (1 bit) : Start bit
P (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A (1 bit) : Acknowledge bit.
Addr (7 bits): I2C 7 bit device address.
subAddr (8 bits): Internal address
Data (8 bits): A plain data byte.

Which is what your sensor is expecting. If i2c_burst_write as
implemented by i2c_stm32lx.c driver generates

S Addr Wr [A] subAddr [A] S Addr Wr [A] Data [A] Data [A] ... [A] Data
[A] P

that's wrong. I don't have an STM32 MCU device to try it out but if I
look at the driver's code it seems to confuse I2C_MSG_STOP and
I2C_MSG_RESTART flags. The I2C_MSG_STOP flag is missing completely from
the source code and the decision whether to generate the stop bit is
based on I2C_MSG_RESTART flag. That feels wrong and would result exactly
in the kind of behavior you described.

It would be best to fix the driver code but a quick workaround is to use
i2c_write() function. The i2c device internal address subAddr should be
sent as buf[0] and the first data byte should be sent as buf[1].


Join to automatically receive all group messages.