cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L476 I2C speed setting accurately?

jiayuan
Associate II
Posted on September 24, 2016 at 01:37

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-speed
2 REPLIES 2
Posted on September 24, 2016 at 02:27

[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&currentviews=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?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jiayuan
Associate II
Posted on September 24, 2016 at 04:21

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