cancel
Showing results for 
Search instead for 
Did you mean: 

[error report] STM32F1 I2C HAL BUG I2C_MasterTransmit_TXE

justas23
Associate II
Posted on October 18, 2015 at 00:09

Here is original function

static HAL_StatusTypeDef I2C_MasterTransmit_TXE(I2C_HandleTypeDef *hi2c)

{

        /* Write data to DR */

      hi2c->Instance->DR = (*hi2c->pBuffPtr++);

      hi2c->XferCount--;

  if(hi2c->XferCount == 0)

  {

    /* Disable BUF interrupt */

    __HAL_I2C_DISABLE_IT(hi2c, I2C_IT_BUF);

  }

  return HAL_OK;

}

I found that in runtime this function is entered with XferCount already 0.

As there is no protection from this situation unknown data is put to DR register.

Moreover XferCount is decremented to 0xFFFF and the fun begins.

I've workarounded this problem by editing I2C_MasterTransmit_TXE function:

static HAL_StatusTypeDef I2C_MasterTransmit_TXE(I2C_HandleTypeDef *hi2c)

{

  if(hi2c->XferCount == 0)

  {

    /* Disable BUF interrupt */

    __HAL_I2C_DISABLE_IT(hi2c, I2C_IT_BUF);

  } else {

        /* Write data to DR */

      hi2c->Instance->DR = (*hi2c->pBuffPtr++);

      hi2c->XferCount--;

  }

  return HAL_OK;

}

#bug-i2c-stack-overflow-stm32f1
3 REPLIES 3
Amel NASRI
ST Employee
Posted on October 19, 2015 at 15:33

Hi riabovas.justas,

Could you please provide us more details on the case that leads to enter ''I2C_MasterTransmit_TXE'' with XferCount already 0?

It is expected to run ''I2C_MasterTransmit_BTF'' at the end of transmission, not I2C_MasterTransmit_TXE. 

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Amel NASRI
ST Employee
Posted on October 20, 2015 at 12:33

Hi riabovas.justas,

It seems that the reported issue may occur when data size is 1 byte. This particular case will be managed as a limitation to be fixed in coming releases.

Do you confirm that you are in the same context?

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

justas23
Associate II
Posted on April 19, 2016 at 23:53

Sorry for a little delayed answer.

I haven't checked in what situation function is entered with XferCount set to 0.

Thank you for response!