cancel
Showing results for 
Search instead for 
Did you mean: 

I2C on STM32L151CC dies intermittently

PGogt
Associate III

I have a tilt sensor KX112 connected to the STM32L151CC on I2C2. It seems to work fine but at times the I2C bus comes up as busy and the sensor cannot be read. Rebooting the board solves the problem for a while but it crops up again. I am running the board on an external 16Mhz crystal but the processor is configured to run at 8Mzh. The i2c bus is configured to run at 100Khz, 7 bit address. How can i solve this issue?

Hooking up my sensor to a stm32L152 discovery board does not show bus busy but throws up AF error. I could not get the discovery board to read the sensor even once.

The same sensor connected to a STM32F091 works flawlessly.

7 REPLIES 7

Probably going to want to get it on a logic-analyzer and figure out what's going awry. Have the STM32 trigger when it senses and issue, or misses a NACK.

Make sure you have suitable pull-up resistors.

If the slave device is getting confused or into an odd state it might lock up the bus. ie clamping SDA low.

You might want to add code to clock the slave device out of such a condition, and then try to re-establish communications.

Could relate to the speed at which you're communicating, or the quality of the signal edges, etc. Or potential conflicting with other slaves on the bus, or attempts by multiple threads to use the I2C bus concurrently rather than an orderly fashion.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
We observe exactly what you have mentioned. The bus is clamping SDA low. The speed is 100Khz, I am using freertos. All reads are happening in one single thread so no cross thread access to I2c.
TDK
Guru

verify pins aren’t in use by other peripherals on the board. Disconnect the slave to see if it could be misbehaving. If so, cycling SCL 9x on startup will clear it.

If you feel a post has answered your question, please click "Accept as Solution".
PGogt
Associate III
No the pins are not used by any other peripherals. The slave is working successfully on stm32f091c and has no errors. Will try cycling SCL.

With the F091 vs L151 comparison, are the voltages, bus length, circuit topology, and pull-up's equivalent?

Multiple boards involved? Well bonded grounds?

I would suspect the L151's I2C IP is a much earlier design than that of the F091. Might want to look over the errata, and look for others seeing issues/anomalies.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

By inserting a series resistor one order of magnitude smaller than the pullup, you can find out which party pulls down SDA.

As Clive said, the older I2C module has more quirks. ST does not always propagate a known erratum to errata sheets of all models where given module is used, so you may want to read errata of other STM32 too.

I grew tired of trying to rely on the documentation and work around all individual issues, published or not. I simply use timeout and restart I2C module and the bus when it happens. I've already used bitbanged master, too.

JW

Thanks waclawek.jan looks like I have to do the same. Reset the i2c module every time this happens. Let me give it a try.