2012-10-31 06:26 AM
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. #stm32f4-i2c-issues-not-solved2012-10-31 08:05 AM
Thanks for the information.
I2C is a known source of frustration with STM32 controllers...I have just spent the last few hours of my life trying to get the STM32F4 Discovery board...That sounds rather heroic ...;-)
2012-10-31 08:51 AM
Most I2C slave devices don't have an async reset, when they go pear-shaped you just have to clock them out.
A BSY on the controller side is typically because someone is holding SDA low.2014-12-16 04:38 AM
I am also facing same problem.I have sparkfun 9DOF stick out of which only magnetometer (slave address = 0x3C) is working
but if I rotate magnetometer for heading test i2c communication suddenly stops. In case of accelerometer adxl345 (slave address = 0xA6) and gyroscope itg3200 (slave address = 0xD0) I am able to write in registers of these to sensor for initializing them.But after we send request for read then i2c communication halt and busy flag is continuously remain high.It is clear signs of i2c implementation bug in stm32f4.By the way I tried your methods still those fail for accelerometer and gyroscope. So I think arduino (AVR) is 100 times better than stm32.Because it works smoothly with i2c. From vikrant8051, India2018-10-08 12:59 PM
This was really helpful for me too. I had similar problems. Thank you for sharing and saving a lot of time!! I owe you a beer!
2019-02-25 02:18 AM
@Community member : You're the man! Again... :D
2019-06-11 08:23 AM
Encontré tarde este hilo, 3 semanas intentando resolver el problema con el bus I2C1, al final, me ayudo mucho tu publicación para comprender mas, una solución diferente que encontré, es esperar unos cuantos mili-segundos en un bucle, después de un momento de espera iniciar la comunicación I2C. fue mi solución, por si ha alguien mas le sirve. @rovingburko Thanks, you helped me understand
2019-10-19 04:41 AM
can you provide some Code?
stuck on the same problem