AnsweredAssumed Answered

stm32f407vgt - I2c2 BUSY flag hangs from after RCC enabled and wont be cleared

Question asked by Vidar (Z) on Aug 11, 2014
Latest reply on Aug 11, 2014 by Vidar (Z)

First of all, I know there are other threads herein which deals with the I2Cx BUSY flag problem, and I have tried the solutions suggested in them to no relieve. Therefor I now, as a last resort  opens a new thread about the same topic.

The BUSY flag is set in the same moment as the I2C pheripheral clock is enabled in line 6 (RCC). The BUSY then remains set except for when i tried to do a pheripheral reset. As long as the reset was asserted BUSY was not set, but as soon it was released again BUSY was set again.

The SCL and SDA pins are both high and remains high. I am not able to see any glitches using an oscilloscope. I am able to set or clr both pins by either doing it in sw or by shorting pins to ground so there are nothing keeping the bus high by force. I have also tried to generate both  stop and start conditions on the bus, but the BUSY flag remains high. I have also tried to enable the I2C block before initlaising it to no use. I am stuck.

Then I have also tried to reorder the order things are done, i.e. when to enable clocks and to initialize I2C befor GPIOs and such and many other not so smart variants youdt to have tried it. Its always the same result. As soon as the pheripheral clock for the I2C is turned on the BUSY flag goes on and remains on.

I use many other features on the chip like DCIM and SPI and these works like expected, it's only the I2C2 that does not work right now.

If you have the time and skill I would be very happy for an helping hand.

Thanks in advance (see code below)
Vidar (Z)
The code I use for initialization is given below, but first the definition I use in the code and which gives you the GPIOs used and such

(EDIT: Tagged my error in red, should read GPIO_Mode_AF)

01.// I2C interface
02.#define I2C_CHANNEL               I2C2
03.#define I2C_AF                    GPIO_AF_I2C2
04.#define I2C_RCC                   RCC_APB1Periph_I2C2
05.#define I2C_GPIO_RCC              RCC_AHB1Periph_GPIOB
06.#define I2C_PORT                  GPIOB
07.#define I2C_READ                  0x01
08.#define I2C_WRITE                 0x00
10.#define I2C_SCL_PIN               GPIO_Pin_10                 /* PB.10 - AF */
11.#define I2C_SCL_PORT              GPIOB                       /* GPIOB */
12.#define I2C_SCL_RCC               RCC_AHB1Periph_GPIOB
13.#define I2C_SCL_PIN_NR            GPIO_PinSource10
15.#define I2C_SDA_PIN               GPIO_Pin_11                 /* PB.11 - AF */
16.#define I2C_SDA_PORT              GPIOB                       /* GPIOB */
17.#define I2C_SDA_RCC               RCC_AHB1Periph_GPIOB
18.#define I2C_SDA_PIN_NR            GPIO_PinSource11

01.void I2C_init(void)
03.  GPIO_InitTypeDef GPIO_InitStructure;
04.  I2C_InitTypeDef  I2C_InitStructure;
06.  RCC_APB1PeriphClockCmd(I2C_RCC, ENABLE);
07.  RCC_AHB1PeriphClockCmd(I2C_GPIO_RCC, ENABLE);
09.  /* Configure port pins used by I2C */
10.  GPIO_InitStructure.GPIO_Pin = I2C_SCL_PIN | I2C_SDA_PIN;
11.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
12.  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
13.  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
14.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
15.  GPIO_Init(I2C_PORT, &GPIO_InitStructure);
17.  I2C_PORT->BSRRL = I2C_SCL_PIN | I2C_SDA_PIN; // Set high
19.  /* Connect I2C dedicated port pins to use the alternative function */
23.  /* Configure I2C */
24.  I2C_InitStructure.I2C_ClockSpeed = 100000;
25.  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
26.  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
27.  I2C_InitStructure.I2C_OwnAddress1 = 0x00;
28.  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
29.  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
31.  I2C_Init(I2C_CHANNEL, &I2C_InitStructure);
33.  // enable I2C_CHANNEL