-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Describe the bug
The speed for the I2C5 peripheral is always ~16.8kHz and not the expected 100kHz on the Nucleo-H723ZG board and possibly other H7 variants. It does not change for different values of Wire.setClock(values)
. The other I2C peripherals behave as expected.
To Reproduce
Minimal reproducible example code:
#include <Wire.h>
void setup() {
// set Wire to Pins associated with I2C5:
Wire.setSDA(PC_10);
Wire.setSCL(PC_11);
Wire.begin();
Wire.setClock(100000);
// send any I2C message
Wire.beginTransmission(0x24);
Wire.write(0);
Wire.endTransmission();
}
void loop() {
}
Results in ~16.8kHz on SCL Pin PC11 (see image)
Expected behavior
Expect 100kHz clock speed.
Screenshots
Measurement of Pin PC 10 (red) and PC11 (brown):
Clock speed around 16.8kHz.
Desktop (please complete the following information):
- OS: Windows 11
- Arduino IDE version: 2.3.3
- STM32 core version: 2.81
- Tools menu settings: default
- Upload method: Mass storage
Board (please complete the following information):
- Name: Nucleo-H723ZG
- Hardware Revision: Rev E01
- Extra hardware: no
Additional context
I think that the issue is in the i2c_getClkFreq(I2C_TypeDef *i2c)
function. I single stepped the code and this snipped always returns 0 for the I2C5 peripheral clock frequency clkSrcFreq
:
Arduino_Core_STM32/libraries/Wire/src/utility/twi.c
Lines 415 to 424 in 42e0262
#if defined(I2C5_BASE) | |
if (i2c == I2C5) { | |
#if defined(RCC_PERIPHCLK_I2C5) || defined(RCC_PERIPHCLK_I2C35) | |
#ifdef RCC_PERIPHCLK_I2C5 | |
clkSrcFreq = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_I2C5); | |
#else | |
clkSrcFreq = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_I2C35); | |
#endif | |
#endif | |
} |
For the working I2C1 Peripheral with the same clock source there is handling for that case:
Arduino_Core_STM32/libraries/Wire/src/utility/twi.c
Lines 207 to 254 in 42e0262
if (clkSrcFreq == 0) | |
#endif | |
{ | |
#ifdef __HAL_RCC_GET_I2C1_SOURCE | |
switch (__HAL_RCC_GET_I2C1_SOURCE()) { | |
#ifdef RCC_I2C1CLKSOURCE_HSI | |
case RCC_I2C1CLKSOURCE_HSI: | |
clkSrcFreq = HSI_VALUE; | |
break; | |
#endif | |
#ifdef RCC_I2C1CLKSOURCE_HSIKER | |
case RCC_I2C1CLKSOURCE_HSIKER: | |
clkSrcFreq = __LL_RCC_CALC_HSIKER_FREQ(LL_RCC_HSIKER_GetDivider()); | |
break; | |
#endif | |
#ifdef RCC_I2C1CLKSOURCE_SYSCLK | |
case RCC_I2C1CLKSOURCE_SYSCLK: | |
clkSrcFreq = SystemCoreClock; | |
break; | |
#endif | |
#if defined(RCC_I2C1CLKSOURCE_PCLK1) || defined(RCC_I2C1CLKSOURCE_D2PCLK1) | |
#ifdef RCC_I2C1CLKSOURCE_PCLK1 | |
case RCC_I2C1CLKSOURCE_PCLK1: | |
#endif | |
#ifdef RCC_I2C1CLKSOURCE_D2PCLK1 | |
case RCC_I2C1CLKSOURCE_D2PCLK1: | |
#endif | |
clkSrcFreq = HAL_RCC_GetPCLK1Freq(); | |
break; | |
#endif | |
#ifdef RCC_I2C1CLKSOURCE_CSI | |
case RCC_I2C1CLKSOURCE_CSI: | |
clkSrcFreq = CSI_VALUE; | |
break; | |
#endif | |
#ifdef RCC_I2C1CLKSOURCE_PLL3 | |
case RCC_I2C1CLKSOURCE_PLL3: | |
HAL_RCCEx_GetPLL3ClockFreq(&PLL3_Clocks); | |
clkSrcFreq = PLL3_Clocks.PLL3_R_Frequency; | |
break; | |
#endif | |
default: | |
Error_Handler(); | |
} | |
#else | |
Error_Handler(); | |
#endif | |
} |
Metadata
Metadata
Assignees
Labels
Type
Projects
Status