AnsweredAssumed Answered

Sequential receive/transmit

Question asked by Luca R on Aug 28, 2017

I want to implement a slave I2C interface with STM32F411.

I can't know in advance how many bytes are going to be written from the master, or how many bytes are going to be read.

I followed this approach:

check in HAL_I2C_AddrCallback if it has been asked a Read or a Write operation;

if the master wants to read something, then use the HAL_I2C_Slave_Sequential_Transmit_IT to transmit the first byte. When this first byte is correctly sent and acknowledged, the HAL_I2C_SlaveTxCpltCallback is called: there I want to be able to understand if the master wants to receive more bytes or not...but I couldn't find the correct trigger.

I2C bus state is always "STATE_LISTEN", both if it has been requested 1 byte, and if the master wants to read many bytes.


Of course I have the same problem if the master wants to write something: I thought to call the HAL_I2C_Slave_Sequential_Receive_IT to receive 1 byte, and call it again and again until there are data to be written.


In all the I2C examples that can be found under  STM32Cube_FW_F4_V1.16.0\Projects\STM32F411E-Discovery\Examples\I2C the size of Rx and Tx buffer are fixed and predefined , and I couldn't find any useful clue to proceed.


How can I check , being an I2C slave, if the Master sent a STOP condition to end its transaction?