2014-07-10 01:49 AM
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_busy2014-07-17 03:32 AM
Hello,
try to use I2C_DeInit function before initialization.2015-03-11 05:29 PM
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 */
}
}