cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Busy flag after I2C Clock enable, how to solve?

uli stone
Associate II

Hi,

RCC->APB1ENR |= RCC_APB1ENR_I2C2EN;

immeditly after turning on the I2C2 Clock I get a busy flag for I2C2.

Its then reset with:

GPIOF->MODER |= GPIO_MODER_MODER0_1 | GPIO_MODER_MODER1_1;

But when PUPDR is executed, the flag is busy again:

GPIOF->PUPDR &= ~(GPIO_PUPDR_PUPDR0_0 | GPIO_PUPDR_PUPDR1_0);

I can then reset the busy flag with:

I2C2->CR1 |= I2C_CR1_SWRST;

But after deactivating the SWRST the Busy flag is again active.

What is a bit odd, I had yesterday used the same code and had a full working I2C communication. (The selected SCL speed is 100khz, PF0 &PF1 and I'm using the STM32F429DISCOI Board.)

I also tried to use the PF0 and PF1 Pins as GPIO and ground them manual but no luck there as well.

Full I2C Init code:

RCC->APB1RSTR |= RCC_APB1RSTR_I2C2RST;
RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C2RST);
 RCC->APB1ENR |= RCC_APB1ENR_I2C2EN;
 
GPIOF->AFR[0] |= (1 << 2) | (1 << 6);
 
GPIOF->MODER |= GPIO_MODER_MODER0_1 | GPIO_MODER_MODER1_1; 
GPIOF->OTYPER |= GPIO_OTYPER_OT_0 | GPIO_OTYPER_OT_1;      
GPIOF->PUPDR &= ~(GPIO_PUPDR_PUPDR0_0 | GPIO_PUPDR_PUPDR1_0);  
GPIOF->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR0_0 | GPIO_OSPEEDER_OSPEEDR1_0;
I2C2->CR1 |= I2C_CR1_SWRST;
I2C2->CR1 &= ~(I2C_CR1_SWRST);
I2C2->CR2 &= ~(I2C_CR2_FREQ); 
I2C2->CR2 |= 30;
I2C2->CCR &= ~I2C_CCR_CCR;
I2C2->CCR |=  150;
I2C2->TRISE |= (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4);
I2C2->CR1 |= I2C_CR1_PE | I2C_CR1_ACK;

Can someone tell me how to fix this?

Thank you

2 REPLIES 2
S.Ma
Principal

Have you made sure that before you activate the I2C peripheral, the GPIO are connected to it and their levels are high (bus idle mode)?

uli stone
Associate II

Hi,

thank you very much for your time. A cable of my bus got loose.