STM32 FW_F7_V1.3.1 I2C HAL_I2C_Master_Receive() BUG
i tried to port software from F4 to F7 but got HAL_TIMEOUT and wrong reading of data
from functio
n
HAL_I2C_Master_Receive()
i changed the following code
--- stm32f7xx_hal_i2c.c Tue Dec 22 14:36:08 2015
+++ my_stm32f7xx_hal_i2c.c Wed May 18 11:59:02 2016
@@ -197,15 +197,17 @@
* @{
*/
#define TIMING_CLEAR_MASK ((uint32_t)0xF0FFFFFF) /*<! I2C TIMING clear register Mask */
-#define I2C_TIMEOUT_ADDR ((uint32_t)10000) /* 10 s */
-#define I2C_TIMEOUT_BUSY ((uint32_t)25) /* 25 ms */
-#define I2C_TIMEOUT_DIR ((uint32_t)25) /* 25 ms */
-#define I2C_TIMEOUT_RXNE ((uint32_t)25) /* 25 ms */
-#define I2C_TIMEOUT_STOPF ((uint32_t)25) /* 25 ms */
-#define I2C_TIMEOUT_TC ((uint32_t)25) /* 25 ms */
-#define I2C_TIMEOUT_TCR ((uint32_t)25) /* 25 ms */
-#define I2C_TIMEOUT_TXIS ((uint32_t)25) /* 25 ms */
-#define I2C_TIMEOUT_FLAG ((uint32_t)25) /* 25 ms */
+
+#define I2C_TIMEOUT_ADDR ((uint32_t)100) /* 100 ms */
+#define I2C_TIMEOUT_BUSY ((uint32_t)100) /* 100 ms */
+#define I2C_TIMEOUT_DIR ((uint32_t)100) /* 100 ms */
+#define I2C_TIMEOUT_RXNE ((uint32_t)100) /* 100 ms */
+#define I2C_TIMEOUT_STOPF ((uint32_t)100) /* 100 ms */
+#define I2C_TIMEOUT_TC ((uint32_t)100) /* 100 ms */
+#define I2C_TIMEOUT_TCR ((uint32_t)100) /* 100 ms */
+#define I2C_TIMEOUT_TXIS ((uint32_t)100) /* 100 ms */
+#define I2C_TIMEOUT_FLAG ((uint32_t)100) /* 100 ms */
+
/**
* @}
*/
@@ -613,6 +615,7 @@
}
}
+
/**
* @brief Receives in master mode an amount of data in blocking mode.
* @param hi2c : Pointer to a I2C_HandleTypeDef structure that contains
@@ -627,6 +630,7 @@
{
uint32_t sizetmp = 0;
+
if(hi2c->State == HAL_I2C_STATE_READY)
{
if((pData == NULL ) || (Size == 0))
@@ -659,19 +663,15 @@
sizetmp = Size;
}
+ /* Clear RXNE Flag */
+ uint8_t dummy=hi2c->Instance->RXDR;
+
do
{
/* Wait until RXNE flag is set */
- if(I2C_WaitOnRXNEFlagUntilTimeout(hi2c, I2C_FLAG_RXNE) != HAL_OK)
+ if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_RXNE, RESET, Timeout) != HAL_OK)
{
- if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
- {
- return HAL_ERROR;
- }
- else
- {
return HAL_TIMEOUT;
- }
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
/* Write data to RXDR */
problem was that function
I2C_WaitOnRXNEFlagUntilTimeout(hi2c, I2C_FLAG_RXNE) is called with a flag as timeout value and that it returned because a stop flag was detected ,
with
hi2c->
ErrorCode
= HAL_I2C_ERROR_NONE
and return= HAL_ERROR
so function
HAL_I2C_Master_Receive()
returned with HAL_TIMEOUT and leaving RXNE flag set.
next read returned wrong values because RXNE flag was still set.
best regards