KL25Z SPI SendBlock

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

KL25Z SPI SendBlock

Jump to solution
976 Views
xiaocongfu
NXP Employee
NXP Employee

Hello,

I have a problem when I use SPI in KL25Z to send data.

Configuration of SPI is:

29012_29012.PNGCapture1.PNG

The code used to send data:

uint16_t Test_VBA_Buffer;

uint8_t SM1_Send[3];

SM1_Send[0] = 0;

SM1_Send[1] = Test_VBA_Buffer>>2;

SM1_Send[2] = Test_VBA_Buffer<<6;

SM1_SendBlock(SM1_Data, SM1_Send, sizeof(SM1_Send));

  while (!SM1_GetBlockSentStatus(SM1_Data)) {       

  SM1_Main(SM1_Data);

}

Here 'SM1_Send' is 24 bits.

The problem is as shown:

29014_29014.JPGimage1.JPG

Sometimes a delay appears in the middle of CS and Clock. The length of delay also varies: normally 8 bits but sometimes 1 bit. With this delay, I can't get correct output as expected.

Does someone have the same problem or have a solution?

Thanks,

Xiaocong

0 Kudos
1 Solution
649 Views
marek_neuzil
NXP Employee
NXP Employee

Hello,

It seems that your issue is caused by another interrupt routine (long execution of an interrupt routine with the same priority or a part of the code with disabled interrupts). The issue can be caused by another device driver or part of your application.

You can also try to use higher core clock frequency and/or lower speed of the SPI (Clock rate).

Best Regards,

Marek Neuzil

View solution in original post

0 Kudos
4 Replies
649 Views
marek_neuzil
NXP Employee
NXP Employee

Hello,

You are using the SPIMaster_LDD component in the polling mode (without interrupts), the SPI contains buffer for one character only and the main function is used for transmitting of data (this function writes data into SPI data register).

According to your screenshot of the CS and Clock signals there are captured three sequences of SM1_Send array send (3 x 3 bytes of data). You can see that the second sequence is split into two part - 1 byte of data, a delay and 2 bytes of data. The delay can be caused by any interrupt of your application during the while loop of your code.

If you want to ensure that all data are send in one block without any delay in the polling mode of the SPI device you must disable all interrupts during the while loop (for example by the __DI() function) or you can use the SPI interrupt with the highest priority to ensure that data are stored in the output buffer when the output buffer is empty.

Best Regards,

Marek Neuzil

0 Kudos
649 Views
xiaocongfu
NXP Employee
NXP Employee

Hello,

Thank you for your answer.

I have set the SPI interrupt with the highest priority, but I still have the same problem.

sm1.PNG

0 Kudos
650 Views
marek_neuzil
NXP Employee
NXP Employee

Hello,

It seems that your issue is caused by another interrupt routine (long execution of an interrupt routine with the same priority or a part of the code with disabled interrupts). The issue can be caused by another device driver or part of your application.

You can also try to use higher core clock frequency and/or lower speed of the SPI (Clock rate).

Best Regards,

Marek Neuzil

0 Kudos
649 Views
xiaocongfu
NXP Employee
NXP Employee

Hello,

Yes I have found that there are other interrupts with the same priority as the SPI. I set the others to medium priority, the amount of the delay has much decreased(even there are still some delay, it doesn't affect the calculation).

Thank you.

Best Regards,

Xiaocong

0 Kudos