Continuous Transfer LPSPI S32K14x

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

Continuous Transfer LPSPI S32K14x

Jump to solution
436 Views
Khaledag
Contributor II

I am wondering how exactly a code for the Continuous Transfer looks like. 

void receiveBytes(uint8_t address, uint8_t *buffer, uint8_t numBytes)
{
uint8_t i;
address = address|0x40;  // multibyte  enabled
address = address|0x80;  // write enabled
while((LPSPI0->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0) {}
    LPSPI0->TDR =  LPSPI_TDR_DATA(address) ;
    LPSPI0->SR |= LPSPI_SR_TDF_MASK; /* Clear TDF flag */
    while((LPSPI0->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0){}
    LPSPI0->RDR ;
    LPSPI0->SR |= LPSPI_SR_RDF_MASK; /* Clear RDF flag */
for (i = 0 ; i < numBytes; ++i) {
  while ((LPSPI0->SR & LPSPI_SR_TDF_MASK) >> LPSPI_SR_TDF_SHIFT == 0) {}
  LPSPI0->TDR = LPSPI_TDR_DATA(0x00);
  while ((LPSPI0->SR & LPSPI_SR_RDF_MASK) >> LPSPI_SR_RDF_SHIFT == 0) {}
  *buffer++ = LPSPI0->RDR;
 
}
LPSPI0->SR |= LPSPI_SR_RDF_MASK; /* Clear RDF flag */
 
 
}
 
I have this code here, and I would like to receive the bytes after one another with the CS staying low all the time. 
I tried controlling the CS pin but the clock was then always working as seen on the scope even if the CS pin was high. 
And if I wanna use the Continuous Transfer mode, do I also need to add a few SPI settings or just add the lines iin the transfer and receive functions?

Thanks in advance!
0 Kudos
Reply
1 Solution
424 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

this one would work for continuous selection

#define TCR_COMMAND LPSPI_TCR_CPOL_MASK|LPSPI_TCR_CPHA_MASK|LPSPI_TCR_PRESCALE(2)|LPSPI_TCR_PCS(1)|LPSPI_TCR_FRAMESZ(7)

void LPSPI1_receive(uint8_t address, uint8_t *rxBuf, uint8_t nbytes)
{
uint8_t i=1;
 
LPSPI1->TCR = TCR_COMMAND | LPSPI_TCR_CONT(1);
while((LPSPI1->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0){};
LPSPI1->TDR = 0xC0|address;
while((LPSPI1->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0){};
LPSPI1->TDR = i++; // write dummy byte
while((LPSPI1->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0){};
(void)LPSPI1->RDR;
while(i <= nbytes)
{
while((LPSPI1->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0);
LPSPI1->TDR = i++; // write dummy byte
while((LPSPI1->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0);
*rxBuf++ = LPSPI1->RDR;
};
LPSPI1->TCR = TCR_COMMAND | LPSPI_TCR_CONT(0);
while((LPSPI1->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0);
*rxBuf++ = LPSPI1->RDR;
 
}
 
BR, Petr

View solution in original post

0 Kudos
Reply
2 Replies
425 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

this one would work for continuous selection

#define TCR_COMMAND LPSPI_TCR_CPOL_MASK|LPSPI_TCR_CPHA_MASK|LPSPI_TCR_PRESCALE(2)|LPSPI_TCR_PCS(1)|LPSPI_TCR_FRAMESZ(7)

void LPSPI1_receive(uint8_t address, uint8_t *rxBuf, uint8_t nbytes)
{
uint8_t i=1;
 
LPSPI1->TCR = TCR_COMMAND | LPSPI_TCR_CONT(1);
while((LPSPI1->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0){};
LPSPI1->TDR = 0xC0|address;
while((LPSPI1->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0){};
LPSPI1->TDR = i++; // write dummy byte
while((LPSPI1->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0){};
(void)LPSPI1->RDR;
while(i <= nbytes)
{
while((LPSPI1->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0);
LPSPI1->TDR = i++; // write dummy byte
while((LPSPI1->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0);
*rxBuf++ = LPSPI1->RDR;
};
LPSPI1->TCR = TCR_COMMAND | LPSPI_TCR_CONT(0);
while((LPSPI1->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0);
*rxBuf++ = LPSPI1->RDR;
 
}
 
BR, Petr
0 Kudos
Reply
417 Views
Khaledag
Contributor II

Thank you very much

 

0 Kudos
Reply