cancel
Showing results for 
Search instead for 
Did you mean: 

I2C controller getting false arbitration lost

psusi
Associate II

I've enabled the I2C controller and ask it to send a start condition on the bus, and it does, however, as soon as I write a data byte to the TX register, it releases the bus and raises an arbitration lost flag. How can this be possible when there is nothing on the bus and SDA is high the entire time?

 // Enable port B clock

 RCC->AHBENR |= 0x40000u;

 // Set PB6 and 7 to alternate function

 GPIOB->MODER |= (0x2u << GPIO_MODER_MODER6_Pos);

 GPIOB->MODER |= (0x2u << GPIO_MODER_MODER7_Pos);

 // Set alternate function to I2C

 GPIOB->AFR[0] |= (0x4u << GPIO_AFRL_AFRL6_Pos);

 // Enable I2C module clock

 RCC->APB1ENR |= 0x200000;

 // PRESC = 1, SCLL = 0x13, tSCLL = 20 x 250 nS = 5.0 uS, SCLH = 0xF, tSCLH = 16 x 250 nS = 4.0 uS, tSCL = 10 uS

 // SDADEL = 2, tSDADEL = 2 x 250 nS = 500 nS, SDLDEL = 4, tSCLDEL = 5 x 250 nS = 1250 nS

 I2C1->TIMINGR = 0x10540F13;

 // Enable I2C

 I2C1->CR1 = 0x01u;

 // Start condition

 I2C1->CR2 |= 0x52000u;

2 REPLIES 2

Always start with stating, which STM32 are you using.

> // Set alternate function to I2C

> GPIOB->AFR[0] |= (0x4u << GPIO_AFRL_AFRL6_Pos);

Okay and where's the setting AF for PB7?

Also, see the Delay after an RCC peripheral clock enabling erratum.

JW

psusi
Associate II

D'oh! Thanks! It's working now.