Hi NXP Community,
I'm working with S32K388 and configuring LPSPI baud rate. I have a question about the SCKDIV value calculation.
**My Understanding:**
According to the S32K3xx Reference Manual, the LPSPI baud rate formula is:
```
SCK = LPSPI_CLK / (PRESCALE_DIV × (SCKDIV + 1))
```
**My Configuration:**
- LPSPI clock source: AIPS_SLOW_CLK = 40 MHz
- Target baud rate: 1 MHz
- PRESCALE = 0 (÷1)
**My Calculation:**
```
SCKDIV = (LPSPI_CLK / Baud) - 1
SCKDIV = (40 MHz / 1 MHz) - 1 = 39
```
**S32DS Generated Code:**
However, when I use S32DS to generate the configuration, it gives:
```c
LPSPI_CCR_SCKDIV(38U) // SCKDIV = 38
```
**Question:**
With SCKDIV=38, the actual division factor is 39, which means:
```
Actual Baud = 40 MHz / 39 = 1,025,641 Hz ≈ 1.026 MHz
```
This has about 2.56% error from the target 1 MHz.
Why does S32DS use SCKDIV=38 instead of SCKDIV=39? Is there a different LPSPI clock frequency being used in S32DS configuration, or is there another reason for this choice?
**Additional Context:**
- I'm using S32DS 3.5
- S32K388 reference manual Rev. 6
- The project was created with default clock configuration
Thanks in advance for any clarification!
Best regards
Hi @xlele
First, please note that the latest available version of the S32K3xx Reference Manual is Rev. 12. The revision you are currently using contains preliminary information for the S32K310, S32K311, and S32K3x8 devices, which had not yet been released when that document was published. Therefore, I recommend downloading and referring to the latest revision of the RM.
Regarding the LPSPI baud rate calculation, the description of the SCKDIV field in the Clock Configuration Register (CCR) states that:
Baud rate = Functional Clock ÷ (2^PRESCALE × (SCKSET + SCKHLD + 2))
where SCKSET and SCKHLD are derived from SCKDIV ÷ 2.
Considering that SCKDIV = 38:
SCKSET = SCKHLD = 38 ÷ 2 = 19
Baud rate = 40 MHz ÷ (2^0 × (19 + 19 + 2)) = 1 MHz which matches the expected value.
BR, VaneB