AnsweredAssumed Answered

STM32F4 I2C Issues solved

Question asked by burkamshaw.leon on Oct 31, 2012
Latest reply on Dec 16, 2014 by vikrant more
I have just spent the last few hours of my life trying to get the STM32F4 Discovery board I2C working with an ADXL345 Accelerometer. Despite using setup code for the GPIO and I2C identical to examples provided in the peripheral library i have had two major issues.

1. Initially no matter how i initialized the STM32 it would block on the I2C_FLAG_BUSY that is checked before starting an i2c transaction. The resolution to this ended up being that i had to first enable the GPIO clock, then perform GPIO initialization, before enabling the I2C clock and then initializing the I2C!!! If you enable both clocks after each other as per any example i could find it didn't work.

2. Once i actually got the STM32 sending some i2c clocks and data out i noted that the ADXL345 was not responding with an ACK (using an oscilloscope). All addresses were correct but it still didn't work. The resolution to this was to move the GPIO_PinAFConfig function calls to the beginning of my initialization code before i even initialize the GPIO clock. If this isn't done the slave i2c devices seem to be in an unknown state when i start an i2c transaction and are not providing ACK.


I provide this in the hope that i save someone else countless hours of frustration. While i have plenty of microcontroller experience i am new to ST microcontrollers. I hope the rest of my journey isn't as frustrating as i2c was.

Outcomes