cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 I2C Issues solved

rovingburko
Associate
Posted on October 31, 2012 at 14:26

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-solved
7 REPLIES 7
frankmeyer9
Associate II
Posted on October 31, 2012 at 16:05

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 ...;-)

Posted on October 31, 2012 at 16:51

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
vikrant more
Associate II
Posted on December 16, 2014 at 13:38

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,

India

Nix Wayne
Associate III

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!

JulienD
Senior

@Community member​  : You're the man! Again... :D

Erlanyoung
Associate

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

cacciu
Associate II

can you provide some Code?

stuck on the same problem