AnsweredAssumed Answered

I2C busy flag is always set. (without library)

Question asked by Min Seok Kim on Sep 13, 2017
Latest reply on Sep 14, 2017 by Min Seok Kim

MCU : STM32F405

 

I wish to use I2C without library.

But, I got always busy flag on I2C_SR2 register

 

---------------------------------------------------------------------------

void set_gpio_af_i2c()
{
RCC_AHB1ENR |= GPIOBEN;
GPIOB_MODER |= (AF_MODE << MODER10 | AF_MODE << MODER11);
GPIOB_PUPDR |= (PULLUP << PUPDR10 | PULLUP << PUPDR11);
GPIOB_OSPEEDR |= (3 << 20 | 3 << 22);
GPIOB_OTYPER |= ( 1 << 10 | 1 << 11);
GPIOB_AFRH |= (AF4 << AFRH10 | AF4 << AFRH11);
}

---------------------------------------------------------------------------

I use the I2C2(SDA : PORTB10, SCL  : PORTB11). 

Initialize GPIOB10, 11 as af mode4, pull_up open drain, very high speed.

 

---------------------------------------------------------------------------

void i2c_setup()
{
RCC_APB1ENR |= (1 << I2C2EN);
I2C_CR1 |= 1 << SWRST;
I2C_CR1 &= ~(1 << SWRST);

I2C_CR2 |= 42;
I2C_CCR |= 210;
I2C_TRISE = 13;

}

---------------------------------------------------------------------------

And I initialize I2C like this, SWRESET, set PCLK, set CCR, set TRISE

 

---------------------------------------------------------------------------

I2C_CR1 |= 1 << PE;
I2C_CR1 |= 1 << ACK;
I2C_CR1 |= 1 << START;


// /* Wait until SB flag is set
while( !(I2C_SR1 & 1 << SB) );

---------------------------------------------------------------------------

Finally, I start like this, set PE, set ACK, set START

 

But, SB flag dosen't set.

 

SR2's busy flag always set.

 

How I can solve it?

Outcomes