Hi NXP experts:
I recently changed the MCU of my project from S32K118 to S32K312EVB-Q172(using SDK RTD 5.0.0 HF01). Both of them running on FIRC 48Mhz.
However, I stuck at setting I2C Master using Flexio module, target baudrate is 400 kHz.
But I found below issues...
1. The baudrate calculation formula is different from K1 series and K3 series.
In K3 series, the baudrate is calculated by two parameters(I2c timer compare value and I2c FlexIO Prescaler), while in K1 series SDK use baudrate to calculate the parameters.
I reference the SDK code that calculate baudrate using InputClock and Divider as parameters
In S32K3xx: baudRate = (inputClock + divider + 2U) / (2U * ((uint32_t)divider + 2U));
In S32K1xx: Baudrate is assigned by developer and use the baudrate to calculate the divider value and divider value.
So my question is, these formulas don't seem equal to each other, so how can I get the desired baudrate?
I've tried set cmpvalue to 58 and prescaler to FLEXIO_TMR_DECREMENT_ON_FLEXIO_CLK_DIV_1, which should generate 400 kHZ, but my LA measurement stucks at around 295 kHZ.
2. S32 Design Studio Peripherial GUI given inaccurate baudrate calculation.
I change the I2c timer compare value, but the auto-generated baudrate value don't change in GUI and Flexio_I2c_Ip_PBcfg.c
Thanks for the reply in advance!
Hi @acnhyxgxl1
I think it is easier to calculate the baud rate based on the RTD_I2C_UM pdf (as this is how the tool calculates baud rate):
You can solve for the compare value like so:
Baud Rate = CLK / (2 * (CMP + 9))
CMP = (CLK / (BR * 2)) - 9
For a 400kHz baud rate, with FIRC at 48MHz, and assuming CORE_CLK with div = 2:
CMP = (24MHz / (400kHz * 2)) - 9
CMP = 21
Which generates the correct value in the Flexio_I2c_Ip_CS_0_PBcfg.c file:
Keep in mind that the pull-up resistor values can affect rise time and speed. I recommend using 4k7 Ohm resistors for this use case. You can also refer to these materials for sizing the values by calculating them:
Lastly, regarding the GUI and how the baud rate does not change, it is definitely configuration tool bug. The actual baud rate may need to be manually calculated or measured. We'll report the tool bug to internal team. Thank you for informing us.
Best regards,
Julián