cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 I2C2 busy bit stuck high after configuration

FLast.16
Associate

Hi,

Saw this (popular) issue on the Q&A and also found many google result regarding this issue, but none of them solve my issue.

I'm trying to configured I2C2 bus to work with eeprom.

During the configuration, right after setting the I2C RCC clock, the busy bit in SR2 is going up, and never going down, no matter what I try. as a result, the first START command is failed.

I also remove my eeprom device and pullup resistors, and saw that after setting the GPIO to AF I2C, the SDA pin is stay high at 3.3V (and therefore the busy is high).

I try to this errata WA (although not related to the STM32F407), and still have the issue:

https://www.st.com/content/ccc/resource/technical/document/errata_sheet/7d/02/75/64/17/fc/4d/fd/CD00190234.pdf/files/CD00190234.pdf/jcr:content/translations/en.CD00190234.pdf

Any suggestions?

e.g. - setting other I2C (I2C1) with the same code is working OK. the busy bit is going up after setting the I2C RCC, and going down again after setting SDA pin to ALT_FUNC

My code:

//---- I2C2: EEPROM ----//

#define I2C_EEPROM_CLOCKS       (RCC_APB1Periph_I2C2)

#define I2C_EEPROM_CLOCKS_GPIOS   (RCC_AHB1Periph_GPIOB)

#define I2C_EEPROM_ALT_FUNC      (GPIO_AF_I2C2)

#define I2C_EEPROM_PORT        (GPIOB)

#define I2C_EEPROM_SCL_PIN      (GPIO_Pin_10)

#define I2C_EEPROM_SCL_PIN_SRC    (GPIO_PinSource10)

#define I2C_EEPROM_SDA_PIN      (GPIO_Pin_11)

#define I2C_EEPROM_SDA_PIN_SRC    (GPIO_PinSource11)

void ConfigEepromHw(void)

{    

  //------------- INIT I2C2 GPIO's -------------//

  /* Enable APB1 peripheral clock for I2C2x */

RCC_APB1PeriphClockCmd(I2C_EEPROM_CLOCKS, ENABLE);

  /* enable the peripheral clock for the pins used by PF1 for I2C SCL and PF1 for I2C1_SDL*/

RCC_AHB1PeriphClockCmd(I2C_EEPROM_CLOCKS_GPIOS, ENABLE);

   

/* This sequence sets up the I2CxSDA and I2CxSCL pins

* so they work correctly with the I2C peripheral

*/

  SetGpioPin(I2C_DISPLAY_SCL_PIN, I2C_EEPROM_PORT, GPIO_OType_OD, GPIO_PuPd_UP);

  SetGpioPin(I2C_EEPROM_SDA_PIN, I2C_EEPROM_PORT, GPIO_OType_OD, GPIO_PuPd_UP);

   

  /* The I2Cx_SCL and I2Cx_SDA pins are now connected to their AF

* so that the I2Cx can take over control of the pins

*/

GPIO_PinAFConfig(I2C_EEPROM_PORT, I2C_EEPROM_SCL_PIN_SRC, I2C_EEPROM_ALT_FUNC);

GPIO_PinAFConfig(I2C_EEPROM_PORT, I2C_EEPROM_SDA_PIN_SRC, I2C_EEPROM_ALT_FUNC);

  /* Configure I2Cx */

  I2C_DeInit(I2C_EEPROM);

   

  //------------- INIT I2Cx BUS -------------//

  ConfigI2cBus(I2C_EEPROM, I2C_SPEED);

   

  /* Enable the I2Cx peripheral */

  I2C_Cmd(I2C_EEPROM, ENABLE);

}

static void SetGpioPin(uint32_t GPIO_Pin, GPIO_TypeDef* GPIO_Port, GPIOOType_TypeDef GPIO_OType, GPIOPuPd_TypeDef GPIO_PuPd)

{

  GPIO_InitTypeDef GPIO_InitStruct;

  GPIO_InitStruct.GPIO_Pin = GPIO_Pin;

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; 

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStruct.GPIO_OType = GPIO_OType; 

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd; 

GPIO_Init(GPIO_Port, &GPIO_InitStruct);

}

1 REPLY 1
FLast.16
Associate

Sorry - found out this is my fault....

This line is wrong (wrong SCL pin):

SetGpioPin(I2C_DISPLAY_SCL_PIN, I2C_EEPROM_PORT, GPIO_OType_OD, GPIO_PuPd_UP);

Should be:

SetGpioPin(I2C_EEPROM_SCL_PIN, I2C_EEPROM_PORT, GPIO_OType_OD, GPIO_PuPd_UP);