S32K14x: Command Word in LPSPI

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

S32K14x: Command Word in LPSPI

Jump to solution
2,214 Views
bjrajendra
Senior Contributor I

Hello all,

I'm currently working on S32K14x series and LSPI Module.

1. I would like to know what actually is the command word in LPSPI with continuous transfers ?

2. In continuous transfer, it's mentioned the command word is written on a frame size boundary. what does it meant ?

3. For Example, I would like to transfer 8 bytes and with a FRAME_SIZE=7 i.e. 8 bits & CONT=1 & CONTC=1 will allow to transfer 7 bytes continuously. Now, I would like to assert the CS after the last byte i.e 8th Byte. What is the procedure I'd to follow ? Does CONT=0 before transferring 8th byte will work? then what is the use of CONTC?

Kindly help in this regard.

Thanks in advance,

Raju.

Labels (1)
0 Kudos
1 Solution
2,099 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello Raju,

1. 

For a continuous transfer, write a command with CONT bit set.

2. 

If you want to change the command within this continuous transfer, write a new command with CONTC = 1 on a frame size boundary. In your example, the frame size boundary is 8 bits given by previous command that you want to change.

3. 

Write a command with CONT = 1.
Load the Transmit Data Register with 8 bytes.
Write a command with CONTC = 0 to terminate the continuous transfer.

The CONTC bit is used to change the command without terminating the continuous transfer.

Regards,

Daniel

View solution in original post

0 Kudos
8 Replies
2,100 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello Raju,

1. 

For a continuous transfer, write a command with CONT bit set.

2. 

If you want to change the command within this continuous transfer, write a new command with CONTC = 1 on a frame size boundary. In your example, the frame size boundary is 8 bits given by previous command that you want to change.

3. 

Write a command with CONT = 1.
Load the Transmit Data Register with 8 bytes.
Write a command with CONTC = 0 to terminate the continuous transfer.

The CONTC bit is used to change the command without terminating the continuous transfer.

Regards,

Daniel

0 Kudos
2,099 Views
bjrajendra
Senior Contributor I

Hi Daniel,

Thanks for the response.

What I understood is CONT=1 will make the SPI_CS asserted though the FRAME_SIZE has been completed. CONTC=1 always because it indicates continue to transfer and do not terminate else with CONTC=0 makes the current transfer to terminate after the word size irrespective of FRAME_SIZE. Thus, it is recommended to maintain CONT=1 always & change CONTC=0 only while transferring the new communication to bring back the CS to HIGH state. 

1. Is it correct?

2. Also, suggest is it necessary to perform below instructions for every byte transfer ( since my frame size is 8 bits i.e, 1 byte)

while((LPSPI1->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0);       /* Wait for Tx FIFO available */
LPSPI1->TDR = send;                                                                                                 /* Transmit data */
LPSPI1->SR |= LPSPI_SR_TDF_MASK;                                                                    /* Clear TDF flag */

3. What is the purpose of clearing TDF flag after loading the data ?

Raju.

0 Kudos
2,099 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi Raju,

1.

If you don't want to change the command within the continuous transfer, leave CONTC = 0.

2.

This write does nothing.

LPSPI1->SR |= PSPI_SR_TDF_MASK;         /* Clear TDF flag */‍‍

The TDF flag shows the state of the TX FIFO.

To clear the flag, write new data to the TDR register.

BR, Daniel

0 Kudos
2,099 Views
bjrajendra
Senior Contributor I

Hi Daniel,

Thanks for the response.

I used below command (i.e. with RXMSK=1) and transmitted 8 bytes, it worked 

LPSPI1->TCR = 0x7B280007;

But, with (i.e. with RXMSK=0), I don't see any data transfer from the micro. How to rececive the data at the same time.

Kindly help in this regard.

Raju

0 Kudos
2,099 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi Raju,

Please read the RDF flag and if there are new data received, read them from the RDR register.

Thanks,

BR, Daniel

0 Kudos
2,099 Views
bjrajendra
Senior Contributor I

Hi Daniel,

I tried reading but still it's the same. stuck in while loop in the process of RDF flag.

I used the example code but with frame size as 7 i.e. 8 bits and trying to send and receive the data. with RXMSK it's able to send the data otherwise it's not.

Kindly help in this regard.

Raju

0 Kudos
2,099 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi Raju,

The RDF flag is set whenever the RX FIFO contains same data (it is configurable in FIFO Control Register (FCR)).

You can see how many words there are stored in the FIFO by reading the FSR_RXCOUNT.

You can simply add this loop between the TDR writes. 

I don't see any reason why it would be stuck there. 

while(LPSPI1->SR & LPSPI_SR_RDF_MASK)
{
    (void)LPSPI1->RDR;
}

Or you can use interrupts or DMA to read the RX FIFO.

Regards,

Daniel

2,099 Views
bjrajendra
Senior Contributor I

Thanks Daniel,

It really helps.

I was thinking RDF flag will clear once it receives data, as it was using the below line which was mentioned in the example code.

 while((LPSPI1->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0){}

Raju

0 Kudos