AnsweredAssumed Answered

STM32F411: I2C_FLAG_AF set but no I2C interrupt is set

Question asked by Luca R on Sep 3, 2017

I am designing a slave process that shall manage unpredictable write/read request from the master.

Unpredictable: the slave doesn't know in advance how many bytes are going to be written from the master, and how many read.

As a design bas I used the I2C_TwoBoards_AdvComIT example

 

When the master is writing something all works fine:

  1. HAL_I2C_AddrCallback is called, and after a few checks on the address and the transfer direction it is called the

    HAL_I2C_Slave_Sequential_Receive_IT , with "Size amount of data" set to 1 byte

     

  2. HAL_I2C_Slave_Sequential_Receive_IT is continuously called at every HAL_I2C_SlaveRxCpltCallback , until the

    HAL_I2C_ListenCpltCallback is called

 

 

I wanted to follow the same approach on Read requests from the master: i.e. sending out one byte by one, with HAL_I2C_Slave_Sequential_Transmit_IT , until an AF condition is detected.

The STM32F411 got stuck, because the interrupt is never raised.

 

The interrupt is correctly enabled (

__HAL_I2C_ENABLE_IT(hi2c, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR);

),

the AF flag is found to be set (I double checked the SR1, bit10, and of course also the Peripheral Enable PE bit in CR1),

but the interrupt seems not to come (I2C_Slave_AF is never called).

 

Any tips?

 

/Luca

Outcomes