cancel
Showing results for 
Search instead for 
Did you mean: 

I2C HAL_I2C_Master_Transmit HAL_I2C_Master_Receive Timeout behavior

dsurrett
Associate II

I am using an STM32H7 to interface with a TI INA700 power monitor. I am using polled/blocking I2C, in particular HAL_I2C_Master_Transmit to set the register I am interested in reading, followed by HAL_I2C_Master_Receive.  This has been working fine for months, so I know that the implementation is basically correct.

 

I am still trying to confirm (the board is not currently in my possession), but it appears the INA700 has been damaged and is not responding to I2C writes or reads with HAL_I2C_Master_Transmit and HAL_I2C_Master_Receive. When this happens, I see this operation go from taking a few ms to taking > 150 ms, even though I have the Timeout argument of both HAL_I2C_Master_Transmit and HAL_I2C_Master_Receive set to 2ms.

 

I have reading documentation, and the documentation seems to say that the purpose of this timeout is to abort the function call if the I2C transaction doesn't complete within that time period, but I am not seeing that behavior, and I am wondering if I am missing something.

1 REPLY 1
dsurrett
Associate II

I think I may have found the issue, there is a 25ms delay hard coded into HAL_I2C_Master_Tranmist and HAL_I2C_Master_Receive when the bus is busy:

 

 

 

if (I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, I2C_TIMEOUT_BUSY, tickstart) != HAL_OK)
    {
      return HAL_ERROR;
    }

 

 

I2C_TIMEOUT_BUSY is 25ms.  Each sensor interaction takes 6 I2C transactions, so if for some reason the busy throughout, this would end up blocking for 150ms.