Skip to content

Commit 462edd5

Browse files
committed
[NUCLEO_F334R8] Fix I2C clock issue
1 parent 116e3ca commit 462edd5

File tree

1 file changed

+9
-14
lines changed
  • libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F334R8

1 file changed

+9
-14
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F334R8/i2c_api.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
6969
// Enable I2C clock
7070
__I2C1_CLK_ENABLE();
7171

72+
// Configure the I2C clock source
73+
__HAL_RCC_I2C1_CONFIG(RCC_I2C1CLKSOURCE_SYSCLK);
74+
7275
// Configure I2C pins
7376
pinmap_pinout(sda, PinMap_I2C_SDA);
7477
pinmap_pinout(scl, PinMap_I2C_SCL);
@@ -102,22 +105,17 @@ void i2c_frequency(i2c_t *obj, int hz)
102105
- I2C clock source = 64 MHz (System Clock w/ HSI) or 72 (System Clock w/ HSE)
103106
- Analog filter delay = ON
104107
- Digital filter coefficient = 0
105-
- Rise time = 100 ns
106-
- Fall time = 10ns
107108
*/
108109
if (SystemCoreClock == 64000000) {
109110
switch (hz) {
110111
case 100000:
111-
tim = 0x60302730; // Standard mode
112-
break;
113-
case 200000:
114-
tim = 0x00C07AB3; // Fast Mode
112+
tim = 0x10B17DB4; // Standard mode with Rise time = 120ns, Fall time = 120ns
115113
break;
116114
case 400000:
117-
tim = 0x00C0216C; // Fast Mode
115+
tim = 0x00E22163; // Fast Mode with Rise time = 120ns, Fall time = 120ns
118116
break;
119117
case 1000000:
120-
tim = 0x00900B22; // Fast Mode Plus
118+
tim = 0x00A00D1E; // Fast Mode Plus with Rise time = 120ns, Fall time = 10ns
121119
// Enable the Fast Mode Plus capability
122120
__HAL_SYSCFG_FASTMODEPLUS_ENABLE(HAL_SYSCFG_FASTMODEPLUS_I2C1);
123121
break;
@@ -127,16 +125,13 @@ void i2c_frequency(i2c_t *obj, int hz)
127125
} else if (SystemCoreClock == 72000000) {
128126
switch (hz) {
129127
case 100000:
130-
tim = 0x10C08DCF; // Standard mode
131-
break;
132-
case 200000:
133-
tim = 0xA010031A; // Fast Mode
128+
tim = 0x10D28DCB; // Standard mode with Rise time = 120ns, Fall time = 120ns
134129
break;
135130
case 400000:
136-
tim = 0x00E0257A; // Fast Mode
131+
tim = 0x00F32571; // Fast Mode with Rise time = 120ns, Fall time = 120ns
137132
break;
138133
case 1000000:
139-
tim = 0x00A00D26; // Fast Mode Plus
134+
tim = 0x00C00D24; // Fast Mode Plus with Rise time = 120ns, Fall time = 10ns
140135
// Enable the Fast Mode Plus capability
141136
__HAL_SYSCFG_FASTMODEPLUS_ENABLE(HAL_SYSCFG_FASTMODEPLUS_I2C1);
142137
break;

0 commit comments

Comments
 (0)