2017-09-13 06:26 AM
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?
2017-09-13 08:45 AM
Hi
buildorder
,Please make sure that I2C clock is enabled after configuring GPIOs.
Another option is to use another pins combination, if available for the package you are using.
Please let me know if this is working.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2017-09-13 09:35 PM
Thanks for your reply
I have a hard time in 2 days. OMG.. It just a shift probelm..
I should like this.
RCC_AHB1ENR |= 1 << GPIOBEN;
but i did
RCC_AHB1ENR |= GPIOBEN;
-Min Seok