2021-08-17 09:26 AM
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.
2021-08-17 10:43 AM
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.
2021-08-17 10:51 AM
2021-08-17 10:57 AM
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.
2021-08-17 11:05 AM
2021-08-17 12:31 PM
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.
2021-08-17 11:36 PM
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
2021-08-17 11:49 PM