Skip to content

Configure I2C Fast Mode when I2C freq is more than 100kHz #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cores/arduino/stm32/twi.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u
handle->Init.Timing = timing;
#else
handle->Init.ClockSpeed = timing;
handle->Init.DutyCycle = I2C_DUTYCYCLE_2;
/* Standard mode (sm) is up to 100kHz, then it's Fast mode (fm) */
/* In fast mode duty cyble bit must be set in CCR register */
if(timing > 100000)
handle->Init.DutyCycle = I2C_DUTYCYCLE_16_9;
else
handle->Init.DutyCycle = I2C_DUTYCYCLE_2;
#endif
handle->Init.OwnAddress1 = ownAddress;
handle->Init.OwnAddress2 = 0xFF;
Expand Down Expand Up @@ -326,6 +331,12 @@ void i2c_setTiming(i2c_t *obj, uint32_t frequency)
obj->handle.Init.Timing = f;
#else
obj->handle.Init.ClockSpeed = f;
/* Standard mode (sm) is up to 100kHz, then it's Fast mode (fm) */
/* In fast mode duty cyble bit must be set in CCR register */
if(frequency > 100000)
obj->handle.Init.DutyCycle = I2C_DUTYCYCLE_16_9;
else
obj->handle.Init.DutyCycle = I2C_DUTYCYCLE_2;
#endif
/*
else if(frequency <= 600000)
Expand Down