Hi Raju,
This is your code:
while((LPSPI0->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0) {}
LPSPI0->TDR = LPSPI_TDR_DATA(0x7A) ;
while((LPSPI0->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0){}
ret = LPSPI0->RDR ;
LPSPI0->SR |= LPSPI_SR_RDF_MASK; /* Clear RDF flag */
while((LPSPI0->SR & LPSPI_SR_TCF_MASK)>>LPSPI_SR_TCF_SHIFT==0) {}
LPSPI0->SR |= LPSPI_SR_TCF_MASK;
At the time you mask the RDF flag, the TCF flag is already set.
The read-modify-write operation (|=) reads the SR register with the TCF flag == 1 and writes it back to clear RDF.
But this cleared the TCF flag only.
In general, if you want to clear a w1c flag, don't use the read-modify-write operation but simply write the mask to the register.
Not this:
LPSPI0->SR |= LPSPI_SR_RDF_MASK; /* Clear RDF flag */
but this:
LPSPI0->SR = LPSPI_SR_RDF_MASK; /* Clear RDF flag */
Also, the RDF flag cannot be cleared by w1c.
The flag simply informs about the state of the RX FIFO.
You can clear the flag by reading the data from the RX FIFO only.
Regards,
Daniel