cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L1 I2C in Fast Mode

Zoher Ghadyali
Associate
Posted on June 15, 2017 at 22:25

I am using the stm32l1xx_i2c.c code and I am successfully using I2C to interface with a BNO055 IMU. Everything is working perfectly at 100 kHz and now I want to speed that up as much as I can. My PCLK1 frequency is 32 MHz (which I realize is not a multiple of 10 MHz) so I can't reach 400 kHz but I want to get as close to that as possible.

Now, in my I2C_InitStructure, I have set the clock speed to 400000 (400 kHz). I have enabled clock stretching and set the fast mode duty cycle after enabling I2C using:

I2C_StretchClockCmd(I2C2, ENABLE);

I2C_FastModeDutyCycleConfig(I2C2, I2C_DutyCycle_2);

I must clearly be missing something because I am still only measuring 100 kHz on my SCL line.

I apologize if the answer to this question is obvious. I am very new at working with STM32 microcontrollers and I2C.

Thanks!

#stm32l1-i2c
1 REPLY 1
Zoher Ghadyali
Associate
Posted on June 16, 2017 at 17:15

Sorry for posting! I have a problem in initializing I2C but the code I am using handles that and deInits and then re-Inits I2C and that was using a different value for I2C speed than what I thought it was.

TL;DR I don't actually have this problem. Setting the speed of I2C in the I2CInit function is the speed I measure on the SCL line.