SPI clock issue

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

SPI clock issue

1,642 Views
mkdomenico
Contributor II

Hello community,

 

I am trying to implement the SPI module on the S32K144 RevA on a demonstration board. My program loops back MOSI on MISO, sending a number over SPI, which is incremented on reception, and sent again. When this number reaches an arbitrary high (20 000), the red LED is toggled and the number is reset (to 0). In pseudo-code:

 

myNumber = 0

while(1)

   send over SPI(myNumber)

   wait for reception()

   receivedNumber = read from SPI()

   if receivedNumber == 20000

      toggle LED

      myNumber = 0

   else

      increment received number

      assign received number to myNumber

endif

The LED toggling frequency should therefore be directly proportional (or at least, linked) to the SPI frequency. Here is where I cease to understand what is happening:

 

  • When the SPLL_DIV is set to 16MHz and the core clock divided by DIVCORE is set to 32 MHz, the SPI bit period is roughly 250ns, causing the LED to toggle four times a second.

 

  • When the SPLL_DIV is set to 16MHz and the core clock divided by DIVCORE is set to 16 MHz, the SPI bit period is roughly 250ns, causing the LED to toggle twice a second.

 

  • When the SPLL_DIV is set to 32MHz and the core clock divided by DIVCORE is set to 32 MHz, the SPI bit period is roughly 125ns, causing the LED to toggle four times a second.

 

 

  • When the SPLL_DIV is set to 32MHz and the core clock divided by DIVCORE is set to 16 MHz, the SPI bit period is roughly 125ns, causing the LED to toggle twice a second.

 

 

I do not understand why the SPI CLK/bit frequency is seemingly not linked to the LED toggling frequency. (which should be linked to the SPI transmission speed, i.e. SPI CLK frequency)

 

Could you please help me understand this?

 

Thanks in advance,

 

Domenico

Labels (1)
Tags (3)
0 Kudos
1 Reply

1,193 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

The SPI baudrate is given by

 

Baudrate = SPI functional clock / 2^TCR[PRESCALE] / (CCR[SCKDIV] +2)

 

The Functional clock is selected by PPC_LPSPIx register. Not sure what is your configuration in fact, but assuming the XOSC (8Mhz) is selected by PPC_LPSPIx register then using TCR[PRESCALE] =0 and CCR[SCKDIV] = 6 you get

 

Baudrate = 8Mhz / 1 / 8 = 1MHz, Bit period = 1us

 

Then if you are using 16bit SPI frame the single SPI transmission takes 16*1us = 16us

In fact will be more depending complete CCR register setting.

 

Consired there will be no SW and HW overhead then sending of 20000 words takes 20000*16u = 320ms and the LED will toggle with this rate.

BR, Petr