AnsweredAssumed Answered

HAL bug with 1-byte I2C reads

Question asked by nixon.malcolm on Jun 26, 2015
Latest reply on Jul 13, 2015 by Amel N
Greetings all,

I'm using the 1.6.0 release of the STM32F4xx_HAL_Driver, and I believe there's a problem with doing 1-byte I2C reads using the HAL_I2C_Master_Receive_IT function.

Doing reads of more than one byte works fine:
       
  • The user calls HAL_I2C_Master_Receive_IT
  •    
  • The I2C_EV_IRQn interrupt fires, which calls HAL_I2C_EV_IRQHandler
  •    
  • The HAL_I2C_EV_IRQHandler finds I2C_FLAG_MSL set (implying "Master" mode)
  •    
  • The event is processed by the "Master" portion of the HAL_I2C_EV_IRQHandler function
  •    
  • Once all bytes are read, the HAL_I2C_MasterRxCpltCallback function is invoked

Doing a 1-byte read fails as follows:
       
  • The user calls HAL_I2C_Master_Receive_IT
  •    
  • The HAL_I2C_Master_Receive_IT function sets I2C_CR1_STOP (to stop after the first byte)
  •    
  • The I2C_EV_IRQn interrupt fires, which calls HAL_I2C_EV_IRQHandler
  •    
  • The HAL_I2C_EV_IRQHandler finds I2C_FLAG_MSL clear (implying "Slave" mode)
  •    
  • The event is processed by the "Slave" portion of the HAL_I2C_EV_IRQHandler function
  •    
  • The "Slave" portion of HAL_I2C_EV_IRQHandler cannot invoke HAL_I2C_MasterRxCpltCallback
The STM32F429 Reference Manual states that the MSL bit of I2C_SR2 is cleared by hardware after detecting a stop condition. As the I2C_SR2.MSL bit can be cleared by external events; it's probably not a good idea to use it within the ISR to decide whether the user was performing master or slave I2C transactions.

Unfortunately I have the following limitations:
       
  • I can't switch to the DMA version, as I'm out of DMA channels
  •    
  • I can't switch to the polling version, as this is a medical device with hard real-time requirements.
  •    
  • I can't just round up all 1-byte reads to 2 bytes as the part I'm talking to is intolerant to that kind of behavior.
Does anyone know of any other workaround that will function?

Many thanks,
 - Malcolm

Outcomes