Can't send/receive SPI messages longer than 40Byte

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

Can't send/receive SPI messages longer than 40Byte

488 Views
TaehoLee
Contributor I

Hello,

I'm using -> MCU : S32K144, IDE : S32DS ARM 2.2

 

Currently, I'm implementing 176Byte long SPI messages transmit/receive function.

with the SPI bare-metal example code

If I increase the Frame size register in TCR, up to 320bit(4 * 10Byte) it works well

But, If I try to send/receive bigger values it doesn't work. 

 

for example from my code

 uint32_t spi_tx[44] = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA,
 0xB, 0xC, 0xD, 0xE, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14,
 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
 0x29, 0x2A, 0x2B, 0x2C };
 uint32_t spi_rx[44] = {0,};

void LPSPI0_tx(void)
{

for(i=0;i<10;i++)
{
while((LPSPI0->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0);

LPSPI0->TDR = spi_tx[i];
LPSPI0->SR |= LPSPI_SR_TDF_MASK; /* Clear TDF flag */
}

}

void LPSPI0_rx(void)
{

for(j=0;j<10;j++)
{
while((LPSPI0->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0);

spi_rx[j] = LPSPI0->RDR;
LPSPI0->SR |= LPSPI_SR_RDF_MASK;
}

}

If I use i,j = 10 and frame size = 319(320bit) it works well

But, If I use i,j = 11 and frame size = 351(352bit) it doesn't work

 

Can I find an answer?

 

0 Kudos
5 Replies

482 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello @TaehoLee,

First of all, the TDF / RDF flags get set / cleared automatically by the LPSPI module depending on the state of the TX / RX FIFOs.

You did not post the Transmit command that you use, can you share it?

Do you mask the RX data (RXMSK = 1) of this transfer?

Because I don't see how you could receive all the data, there is only 4-word RX FIFO.

Can you poll the RX data within the loop whare you write the TX data?

 

Thank you,

BR, Daniel

 

0 Kudos

480 Views
TaehoLee
Contributor I

Hello,

Basically, I just called spi tx/rx function in the main function like below for the test purpose.

for(;;)
{
LPSPI0_tx();
LPSPI0_rx();

counter++;
}

I didn't mask RX data, Because I also had to receive SPI data

other SPI configurations are the same as the example code

 

Also, I tied MISO/MOSI line together in the PCB(S32K144 EVB)

My intention was that check spi tx/rx data with the same board.

I'm also stranging why rx data have been received and watched at the IDE

 

Can you show the example? how to send/receive 180Byte long SPI messages?

I difficult to find an answer to how to send SPI messages that are longer than 32bit

After increasing frame size register how to send/receive spi data?

 

 

 

0 Kudos

476 Views
danielmartynek
NXP TechSupport
NXP TechSupport

I can modify the example to send and receive 180bytes, but it will take a while.

Can you try masking the RX data, or read it before the RX FIFO overflows?

I think this is the issue here.

 

BR, Daniel

 

0 Kudos

473 Views
TaehoLee
Contributor I

Thank you for your help

After I set RXMSK TX is sending well However, I have to receive SPI rx data also.

I tried to read SPI data after sending 1st SPI word but, RDF was not set.

So, how to read a message during SPI messages transfer?

0 Kudos

462 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @TaehoLee,

I would recommend enabling Receive Data Interrupt (RDIE).

You can set the RXWATER to a higher number so that the interrupt is not called for each word.

Otherwise, you will need to poll the SR_RDF flag and read the data in time to avoid FIFO overflows (SR_REF).

 

BR, Daniel

0 Kudos