2015-10-17 03:09 PM
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-stm32f12015-10-19 06:33 AM
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.
2015-10-20 03:33 AM
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.
2016-04-19 02:53 PM
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!