Skip to content

Commit a11d173

Browse files
committed
Configure I2C Fast Mode when I2C freq is more than 100kHz
For STM32 families that have a DutyCycle init parameter, we need to select the Fast Mode dedicated configuration which will set the fast mode bit in CCR register.
1 parent 10925a1 commit a11d173

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Diff for: cores/arduino/stm32/twi.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,12 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u
261261
handle->Init.Timing = timing;
262262
#else
263263
handle->Init.ClockSpeed = timing;
264-
handle->Init.DutyCycle = I2C_DUTYCYCLE_2;
264+
/* Standard mode (sm) is up to 100kHz, then it's Fast mode (fm) */
265+
/* In fast mode duty cyble bit must be set in CCR register */
266+
if(timing > 100000)
267+
handle->Init.DutyCycle = I2C_DUTYCYCLE_16_9;
268+
else
269+
handle->Init.DutyCycle = I2C_DUTYCYCLE_2;
265270
#endif
266271
handle->Init.OwnAddress1 = ownAddress;
267272
handle->Init.OwnAddress2 = 0xFF;
@@ -326,6 +331,12 @@ void i2c_setTiming(i2c_t *obj, uint32_t frequency)
326331
obj->handle.Init.Timing = f;
327332
#else
328333
obj->handle.Init.ClockSpeed = f;
334+
/* Standard mode (sm) is up to 100kHz, then it's Fast mode (fm) */
335+
/* In fast mode duty cyble bit must be set in CCR register */
336+
if(frequency > 100000)
337+
obj->handle->Init.DutyCycle = I2C_DUTYCYCLE_16_9;
338+
else
339+
obj->handle->Init.DutyCycle = I2C_DUTYCYCLE_2;
329340
#endif
330341
/*
331342
else if(frequency <= 600000)

0 commit comments

Comments
 (0)