S32K3xx Flexio I2C Master Baudrate Calculation Issue

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K3xx Flexio I2C Master Baudrate Calculation Issue

460 Views
acnhyxgxl1
Contributor II

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));

acnhyxgxl1_3-1754652341006.png

In S32K1xx: Baudrate is assigned by developer and use the baudrate to calculate the divider value and divider value.

 tmpDiv = (((int32_t)inputClock + (int32_t)baudRate) / (2 * (int32_t)baudRate)) - 2;

acnhyxgxl1_1-1754651534078.png

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.

acnhyxgxl1_4-1754652723423.png

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

acnhyxgxl1_5-1754652807021.png

acnhyxgxl1_6-1754652822207.png

 

Thanks for the reply in advance!

 

 

 

Labels (2)
Tags (4)
0 Kudos
Reply
1 Reply

441 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

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):

Snag_91a4d9.png

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:

Snag_a4d3dc.png

Snag_a4f3f7.png

CMP = (24MHz / (400kHz * 2)) - 9
CMP = 21

Snag_a52661.png

Which generates the correct value in the Flexio_I2c_Ip_CS_0_PBcfg.c file:

Snag_109bf6e.png

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

0 Kudos
Reply