S32K146 SPI send problem

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

S32K146 SPI send problem

2,724 Views
347996379
Contributor III

Hi ,SDK

In SDK3.0, there are two ways to send SPI, one without blocking and the other with blocking.When I sent SPI data with a blocking function, the program died suddenly.The reason is that in this function "osifError = OSIF_SemaWait(&(lpspistate-> lpspiSemaphore), timeout);", I want to for what reason is caused, how to solve this problem?Thank you very much!

1、LPSPI_DRV_MasterTransfer(uint32_t instance, const uint8_t * sendBuffer, uint8_t * receiveBuffer, uint16_t transferByteCount);

2、LPSPI_DRV_MasterTransferBlocking(uint32_t instance, const uint8_t * sendBuffer, uint8_t * receiveBuffer,uint16_t transferByteCount, uint32_t timeout);

Labels (1)
0 Kudos
12 Replies

2,141 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello 347996379@qq.com,

You need to use a timeout (in ms) longer than what the transfer takes.

Please refer to the SDK documentation in the SDK installation folder:

.../NXP/S32DS_ARM_v2.2/S32DS/software/S32SDK_S32K1xx_RTM_3.0.0/doc/Start_here.html

pastedImage_3.png

Regards,

Daniel

0 Kudos

2,141 Views
347996379
Contributor III

Hi,Daniel.

I'm sorry, maybe I didn't express myself clearly.My SPI communication rate is 1M,SPI can not send two bytes need 100ms, resulting in the program stuck, I do not think it should be caused by the size value of "timeout".Is there another reason?

0 Kudos

2,141 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi 347996379@qq.com,

Hard to say.

Could you please attach a test project so that I can replicate the issue on my side?

Thank you,

BR, Daniel

0 Kudos

2,141 Views
347996379
Contributor III

Hi, Daniel Martnek

as follows:

/*! @brief SPI_PAL instance */
spi_instance_t spi3_palInstance =
{
.instType = SPI_INST_TYPE_LPSPI,
.instIdx = 2U
};

/* SPI Master Configurations */
spi_master_t spi3_MasterConfig0 =
{
.baudRate = 1000000,
.ssPolarity = SPI_ACTIVE_HIGH,
.frameSize = 8,
.clockPhase = READ_ON_EVEN_EDGE,
.clockPolarity = SPI_ACTIVE_LOW,
.bitOrder = SPI_TRANSFER_MSB_FIRST,
.transferType = SPI_USING_INTERRUPTS,
.rxDMAChannel = 255U,
.txDMAChannel = 255U,
.callback = NULL,
.callbackParam = NULL,
.ssPin = 0,
.extension = NULL
};


PINS_DRV_SetMuxModeSel(PORTC, ePIN_14, PORT_MUX_ALT1);//LPSPI0_CS
PINS_DRV_SetMuxModeSel(PORTC, ePIN_1, PORT_MUX_ALT3); //LPSPI0_SOUT
PINS_DRV_SetMuxModeSel(PORTC, ePIN_15, PORT_MUX_ALT3); //LPSPI0_SCK
PINS_DRV_SetMuxModeSel(PORTC, ePIN_0, PORT_MUX_ALT3); //LPSPI0_SIN
//初始化SPI3
SPI_MasterInit(&spi3_palInstance, &spi3_MasterConfig0);

SPI_MasterTransfer(&spi3_palInstance, &data, &RxBuffer[eSPI2], 1);/*Frames are often lost when sending messages here

*/

SPI_MasterTransferBlocking(&spi3_palInstance, &data, &RxBuffer[eSPI2], 1, 1000);/*There is a failure to send the data, and the program will jam.

*/

  • The following picture shows the loss of frames of data sent over a period of 100ms.

pastedImage_1.png

0 Kudos

2,141 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi 347996379@qq.com,

I can't reproduce the issue from the code you sent, that would require a whole test project.

Anyway, please read the return status code of the functions.

After calling the non-blocking transfer function, you can use the LPSPI_DRV_MasterGetTransferStatus() function.

Don't initialize another transfer while there is one already in progress.

Also, you wrote that you cannot send 2 bytes, but you set the transferByteCount of the functions to 1 byte.

Regards,

Daniel

0 Kudos

2,141 Views
347996379
Contributor III

Hi,Danile Martynek;

I think I have known the reason for the loss of my spi sending data. In the SDK routine, the baud rate used by spi is relatively low, such as 50K;There was no problem in the test of this communication rate in my code, but when I continued to increase the communication baud rate of spi to more than 300K, spi began to lose frames of data, and the higher the baud rate, the more serious the frame loss.I tried to increase the clock on the lpspi, but it didn't work.Do you have any ideas?

pastedImage_1.png

0 Kudos

2,141 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi 347996379@qq.com,

At higher baud rates, please use the GPIO-HD (high-drive pins).

It is configurable in PORTn_PCRn[DSE] register of the GPIOs that support it.

In S32K146_IO_Signal_Description_Input_Multiplication.xlsx, IO Signal Table, Column H.

pastedImage_2.png

PE Component inspector:

pastedImage_3.png

The GPIO-HD pins have better current capabilities and can drive the SPI bus faster:

pastedImage_4.png

The signal depends on the electrical parameters of the SPI bus as well.

Instead of increasing the SPI functional clock frequency, try using a higher CORE/SYS_CLK frequency, maybe the issue is related to the CPU overhead.

Regards,

Daniel

0 Kudos

2,141 Views
347996379
Contributor III

Hi , Danile

In "IO Signal Table", S32K146 gpio-hd pins are relatively few, and I have already used all three lpspi. There seems to be no gpio-hd function in my three spi. I wonder if the ordinary GPIO of S32K146 can't support such a high spi communication rate (such as 1M)?Generally speaking, microcontroller spi at 1M communication rate is not high, S32K146 such a powerful microcontroller should not have this problem, if I want to use so high spi communication baud rate must modify the hardware (spi pin specified gpio-hd)?My MCU bus has been configured so high that I really can't figure out where my problem is. Can you help me?

pastedImage_1.png

0 Kudos

2,141 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi 347996379@qq.com,

The GPIO-HD ports have better current capabilities and therefore the slew rate is better.

But the signal depends on the electrical parameters of the bus + on the probe you are using to measure the signal as well.  

You should be able to see the signal on the scope. 

I just mentioned it as a thing to consider.

Please start with an SDK example

pastedImage_2.png

You should be able to increase the baud rate without any problem.

From the description you posted, I'm not able to find the root cause of the issue.

I have already asked you to read the return status code of the functions and to use the LPSPI_DRV_MasterGetTransferStatus() function in case of non-blocking transfers.

Please attach the whole project so that I can test it.

You can create a ticket if you don't what to share the project here:

How to submit a new question for NXP Support 

Thanks,

BR, Daniel

0 Kudos

2,141 Views
347996379
Contributor III

@Daniel Martynek

Hi ,Daniel

I'm sorry for not replying you in time.Since my code was encrypted by the encryption system, it took me some time to work on it.Now that I have added the code to the attachment, please help me to test what causes the loss of frames in spi sending data so seriously. In the code, I sent three spi in a 100ms cycle.

Thank you so much for your assistance!

0 Kudos

2,141 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi 347996379@qq.com,

Thank you for the project.

Could you please disable the internal pullups on the SPI pins - what is the purpose of it?

Also, the TranferStatus() will not return STATUS_SUCCESS if the previously triggered transfer is still in progress.

You can also read the bytesRemained1 value.

And you should not initialize another transfer until the TranferStatus() returns STATUS_SUCCESS.

if(eSPI0 == spiNum)
{
  //LPSPI_DRV_MasterTransferBlocking(0, &data, &RxBuffer[eSPI0], 1, 1000);
  LPSPI_DRV_MasterTransfer(0, &data, &RxBuffer[eSPI0], 1);
  status = LPSPI_DRV_MasterGetTransferStatus(0, &bytesRemained1);
  if(status != STATUS_SUCCESS)
  {
    watchErr1++;
  }
}

BR, Daniel

0 Kudos

2,141 Views
347996379
Contributor III

Hi,Daniel

The reason I enabled the inner pull was to increase his drive, but it didn't work.In my code, it can be deleted. In the picture, I only use one transmission mode, which is non-blocking mode. That is to say, I only use non-blocking mode for data transmission in the same channel, and do not use blocking mode for data transmission.In my code, whether a single channel or multiple channels are used at the same time, I have tried, and the phenomenon of frame loss will occur when the baud rate is relatively high.I don't quite understand what you mean in "And you should not initialize another transfer until the TranferStatus() ".Could it be that when multiple channels are in use, data cannot be transferred until another channel returns STATUS_SUCCESS?Have you solved the problem of data frame loss in my code?

Looking forward to your reply!

0 Kudos