aboutsummaryrefslogtreecommitdiffstats
path: root/src/stm32/stm32f0_i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stm32/stm32f0_i2c.c')
-rw-r--r--src/stm32/stm32f0_i2c.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/stm32/stm32f0_i2c.c b/src/stm32/stm32f0_i2c.c
index ef12145f..9f4bbcc6 100644
--- a/src/stm32/stm32f0_i2c.c
+++ b/src/stm32/stm32f0_i2c.c
@@ -149,17 +149,17 @@ i2c_setup(uint32_t bus, uint32_t rate, uint8_t addr)
gpio_peripheral(ii->sda_pin, ii->function | GPIO_OPEN_DRAIN, 1);
// Set 100Khz frequency and enable
- uint32_t nom_i2c_clock = 8000000; // 8mhz internal clock = 125ns ticks
- uint32_t scll = 40; // 40 * 125ns = 5us
- uint32_t sclh = 32; // 32 * 125ns = 4us
- uint32_t sdadel = 4; // 4 * 125ns = 500ns
- uint32_t scldel = 10; // 10 * 125ns = 1250ns
+ uint32_t nom_i2c_clock = 12000000; // 12mhz internal clock (83.3ns tick)
+ uint32_t scll = 60; // 60 * 83.3ns = 5us
+ uint32_t sclh = 48; // 48 * 83.3ns = 4us
+ uint32_t sdadel = 6; // 6 * 83.3ns = 500ns
+ uint32_t scldel = 15; // 15 * 83.3ns = 1250ns
// Clamp the rate to 400Khz
if (rate >= 400000) {
- scll = 10; // 10 * 125ns = 1250ns
- sclh = 4; // 4 * 125 = 500ns
- sdadel = 3; // 3 * 125 = 375ns
- scldel = 4; // 4 * 125 = 500ns
+ scll = 15; // 15 * 83.3ns = 1250ns
+ sclh = 6; // 6 * 83.3 = 500ns
+ sdadel = 4; // 4 * 83.3 = 333ns
+ scldel = 6; // 6 * 83.3 = 500ns
}
uint32_t pclk = get_pclock_frequency((uint32_t)i2c);