S32K144 LPSPI Framesize

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

S32K144 LPSPI Framesize

Jump to solution
1,220 Views
maurice_mueller
Contributor I

Hi,

I´m using S32K144 Evalboard and the LPSPI communication. I want to change the framesize from 3Bytes

(framesize -1 = 23) to 10 Bytes (framesize - 1 =79) cause I need to read a whole block (8Bytes) of several registers of the SPI device.

When I change the Framsize from 23 to 79 the LPSPI->TCR doesn´t take the new value

void LPSPI1_setFrameSize(const uint8_t framesize)
{

/* check if framesize change is neccessary*/
if( ((LPSPI1->TCR & LPSPI_TCR_FRAMESZ_MASK)>>LPSPI_TCR_FRAMESZ_SHIFT) != (framesize-1) )
{
/* framesize can only be changed if TXMSK bit is cleared by hardware*/
/* wait till TXMSK is cleared to set new TCR Framesize*/
while((LPSPI1->TCR & LPSPI_TCR_TXMSK_MASK)>>LPSPI_TCR_TXMSK_SHIFT==1);
if(framesize <
{
// set minimum framsize to 8Bit
//LPSPI1->TCR &= 0xFFFFF000; /* set first 12 bit (0-11) of 32 bit word to zero*/
LPSPI1->TCR |= LPSPI_TCR_FRAMESZ(8-1);
}
else
{
/* reset framesize: set bit 11-0 to 0!*/
LPSPI1->TCR &= 0xFFFFF000; /* set first 12 bit (0-11) of 32 bit word to zero*/
LPSPI1->TCR |= LPSPI_TCR_FRAMESZ(framesize-1);
}
}
}

Setting the last 12 Bits to Zero does not work! Could someone please tell me how to change the framesize?

kind regards

Maurice

0 Kudos
1 Solution
1,210 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello Maurice,

The TCR register is a FIFO, there might be problems reading it as it is described in the RM, Section 51.4.2.1 Transmit and Command FIFO commands

And your code performs some read-modify-write operations on the TCR register.

Instead of masking the register, you can have commands stored as 32b constants and write the TCR register with the constants when you need to change the command.

 

Regards,

Daniel

View solution in original post

0 Kudos
2 Replies
1,211 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello Maurice,

The TCR register is a FIFO, there might be problems reading it as it is described in the RM, Section 51.4.2.1 Transmit and Command FIFO commands

And your code performs some read-modify-write operations on the TCR register.

Instead of masking the register, you can have commands stored as 32b constants and write the TCR register with the constants when you need to change the command.

 

Regards,

Daniel

0 Kudos
1,197 Views
maurice_mueller
Contributor I

Hi Daniel,

 

Thanks for your answer.

When changing the Code to 

/* reset framesize: set bit 11-0 to 0!*/
LPSPI1->TCR &= 0xFFFFF007; /* set first 12 bit (0-11) of 32 bit word to zero*/
//LPSPI1->TCR |= LPSPI_TCR_FRAMESZ(LPSPI1_TCR_FRMSZE_1);
LPSPI1->TCR |= LPSPI_TCR_FRAMESZ(framesize-1);
}

it will change the framesize.

But now i run into the problem of sending 10 Bytes of data, but TDR size is 32Bit. I tried several possibilities, as found in the NXP community:

// for loop: //for ( index = 0; index < sequence_length; ++index) {
// for loop: //LPSPI1->TDR = &txbuffer[index]; /* Transmit data */

// for loop: //}

// cast to 32Bit words

// LPSPI1->TDR = ((uint32_t)txbuffer[index] << 24)
// |((uint32_t)txbuffer[index+1] << 16)
// |((uint32_t)txbuffer[index+2] << /* Transmit data */
// |((uint32_t)txbuffer[index+3] ) ;
// LPSPI1->TDR = ((uint32_t)txbuffer[index+4] << 24)
// |((uint32_t)txbuffer[index+5] << 16)
// |((uint32_t)txbuffer[index+6] << /* Transmit data */
// |((uint32_t)txbuffer[index+7] ) ;
// LPSPI1->TDR = ((uint32_t)txbuffer[index+8] << 24)
// |((uint32_t)txbuffer[index+9] << 16);

Nothing is working, also receiving more than 32 Bits is not working! 

How should the sending and receiving of data greater than 32Bit word file be implemented? 

 

0 Kudos