2016-09-23 04:37 PM
Hi there,
I got an issue recently when I was trying to set up the I2C speeds for STM32L476RG. I can set it up for an approximate value but never get the exact one. For example, I want to achieve 100 kHz while I can only achieve 104 kHz. I found it has something to do with the tsync value which come from the SCL internal detection delay. In the I2C control Register I can set up PRESC, SCLL, SCLH, SDADEL and SCLDEL, while I can do nothing with tsync. On page 1145 of reference manual (Rev.4), I found some example of the register settings for L4 to reach certain speeds, however the values given in the examples varies quite a lot (what was given is a range actually) and I couldn't find out the exact value of tsync1+ tsync2. I believe this value will affect the I2C speed if we don�t set it correctly.
There is some additional info I found in the AN4235 discussing about what the I2C duration depends on, but there is no explanation to determine the exact tsync1+tsync2..
I also tried the excel version I2C timing tool for the F4 family since there isn't one available for the L4 family. This tool can generate some value but I can't see the calculation behind it so it doesn't help a lot..
Thanks advance for the help!
Best,
Mike Wang
#stm32-i2c-clock-speed2016-09-23 05:27 PM
[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32L476%20I2C%20speed%20setting%20accurately&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https://webcache.googleusercontent.com/search?q%3Dcache:qQphbE1XnlYJ:https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx%2B%26cd%3D1%26hl%3Den%26ct%3Dclnk%26gl%3Dus¤tviews=12]Duplicate Please don't repost the same question, this is a user forum, there is no guarantee of an answer, promptly or otherwise. Rather than repost or bump provide additional information that might expand the pool of respondents.
Assume you'll have to code your own ''fitter'' app to compute timing constants. The silicon is usually the simplest possible implementation, so the math isn't going to be unduly complicated. ie simple counters or dividers I'm not using the L4, as I recall I built a fitter for one of the other STM32 families using a similar mechanism. I'm open to offers for my time. I2C tends to be non time critical, either in the period or duty, and you are unlikely to hit critical paths in the KHz range. Why do you need to hit exactly 100KHz?2016-09-23 07:21 PM
Hi clive,
Thanks for your answer. I'll try to delete the duplicate post..When you say the ''fitter'' app, is it something like an offset? If so, I know what to do with it. If not, can you help explain a little bit more about how you did on F4?Yeah, the I2C is not time critical. I might not explain my problem in a correct way. 104 kHz is Ok for me when the required speed is 100 kHz (I did create an offset, tsync1 + tsync2, to match the timing requirement.) However, when I want to speed to 1MHz, the real speed can only goes up to ~800kHz(with the same offset). Maybe I need to set different offset for each circumstance? Or there is something I totally ignored from the very beginning?Thanks again for your time.Best,Mike