cancel
Showing results for 
Search instead for 
Did you mean: 

I2C_FLAG_BUSY problem

stefano23
Associate II
Posted on July 10, 2014 at 10:49

Good morning,

  I have some problems on I2C bus on STM32F1 micro. I have 8 prototipes board (all with the some mounting). 4 of those works fine and I can read and write the EEPROM on board (a 24xx series standard memory). In the other 4 I see that the firmware stuck on this check:

while ( I2C1->SR2 & I2C_FLAG_BUSY );

This is the first I2C instruction after the initialization. It is possible that I have some mistake in the initialization that cause this problem?

Stefano

#i2c_flag_busy
2 REPLIES 2
valeriagh
Associate II
Posted on July 17, 2014 at 12:32

Hello,

try to use I2C_DeInit function before initialization. 

joachim2
Associate II
Posted on March 12, 2015 at 01:29 What worked for me was : in the stm32f4xx_hal_msp.c In HAL_I2C_Init() function, put the__I2Cx_CLK_ENABLE(); macro after GPIO initialisation.

void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
{
GPIO_InitTypeDef GPIO_InitStruct;
if(hi2c->Instance==I2C3)
{
/* USER CODE BEGIN I2C3_MspInit 0 */
/* USER CODE END I2C3_MspInit 0 */
/* Peripheral clock enable */
// __I2C3_CLK_ENABLE(); // COMMENTED HERE 
/**I2C3 GPIO Configuration 
PC9 ------> I2C3_SDA
PA8 ------> I2C3_SCL 
*/
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF4_I2C3;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF4_I2C3;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USER CODE BEGIN I2C3_MspInit 1 */
__I2C3_CLK_ENABLE(); // PUT HERE INSTEAD TO AVOID BUS BUSY FLAG
/* USER CODE END I2C3_MspInit 1 */
}
}