Hello friends,
I'm trying to use the LPSPI module of Kinetis MKE18F512VLL16 for making a single byte transfer function. I tried to drive the peripheral with both the CMSIS LPSPI driver as well as the NXP Peripheral SDK Library. Tried example codes for both of the libraries with transfer size set to 1. Every time when I run the code, the data transfer function got stuck in the below mentioned while loop and it's not going forward.

I tried debugging step by step, but couldn't find a solution. So I went forward and wrote a bare-metal driver for LPSPI from scratch and that didn't worked either. The bare- metal driver is as follows.
void InitSPI(void){
/* Set pin mux alternative to LPSPI */
PORTB->PCR[14] |= PORT_PCR_MUX(3);
PORTB->PCR[15] |= PORT_PCR_MUX(3);
PORTB->PCR[16] |= PORT_PCR_MUX(3);
PORTB->PCR[17] |= PORT_PCR_MUX(3);
PCC->CLKCFG[PCC_LPSPI1_INDEX] |= PCC_CLKCFG_CGC(0b1);
/* Enable Clock for LPSPI Module */
PCC->CLKCFG[PCC_LPSPI1_INDEX] |= PCC_CLKCFG_PCS(3);
/* FIRC selected as clock source */
LPSPI1->CR |= LPSPI_CR_RTF_MASK; /* Reset Transmit FIFO */
LPSPI1->CR |= LPSPI_CR_RRF_MASK; /* Reset Receive FIFO */
LPSPI1->CR |= LPSPI_CR_DBGEN_MASK; /* Module is enabled in debug mode */
LPSPI1->CFGR1 |= LPSPI_CFGR1_OUTCFG_MASK; /* Output data is tristated when CS is negated */
LPSPI1->CFGR1 |= LPSPI_CFGR1_MASTER_MASK; /* Master Mode configured */
LPSPI1->CFGR1 &= (~LPSPI_CFGR1_NOSTALL_MASK); /* No Stall Disabled */
LPSPI1->CCR |= LPSPI_CCR_SCKPCS(1); /* Delay from the last SCK edge to the PCS negation */
LPSPI1->CCR |= LPSPI_CCR_PCSSCK(1); /* Delay from the PCS assertion to the first SCK edge */
LPSPI1->CCR |= LPSPI_CCR_DBT(2); /* Delay from the PCS negation to the next PCS assertion */
LPSPI1->CCR |= LPSPI_CCR_SCKDIV(2); /* SCK Divider */
LPSPI1->FCR |= LPSPI_FCR_RXWATER(1); /* Receive FIFO Watermark */
LPSPI1->FCR |= LPSPI_FCR_TXWATER(1); /* Transmit FIFO Watermark */
LPSPI1->TCR &= ~(LPSPI_TCR_TXMSK_MASK); /* Trasmit Masked */
LPSPI1->TCR |= LPSPI_TCR_RXMSK(1); /* Receive Masked */
LPSPI1->TCR |= LPSPI_TCR_PRESCALE(3); /* Prescale - 8 */
LPSPI1->TCR |= LPSPI_TCR_WIDTH(1); /* LPSPI in 2 wire mode */
LPSPI1->TCR |= LPSPI_TCR_PCS(3); /* Trasfer using PCS 3 */
LPSPI1->TCR |= LPSPI_TCR_FRAMESZ(8); /* Frame Size 8 bits */
LPSPI1->TCR |= LPSPI_TCR_TXMSK_MASK; /* Trasmit Unmasked */
LPSPI1->CR |= LPSPI_CR_MEN_MASK; /* Module is enabled */
/* Baud Rate = (SrcClk/PRESCALE)/(SCKDIV+2) = (12MHz/8)/(4) = 375 KHz */
}
void SPISendData(uint8_t TxData){
LPSPI1->TCR |= LPSPI_TCR_RXMSK(1); /* Receive Masked */
LPSPI1->TCR |= LPSPI_TCR_TXMSK_MASK; /* Trasmit Unmasked */
LPSPI1->TDR = TxData;
}
uint32_t SPI_ReadData(void){
LPSPI1->TCR &= ~LPSPI_TCR_RXMSK(1); /* Receive Unmasked */
LPSPI1->TCR &= ~(LPSPI_TCR_TXMSK_MASK); /* Trasmit Masked */
return (LPSPI1->RDR);
}
1. What could be the reason behind the NXP LPSPI SDK peripheral library example code getting stuck in the above mentioned while loop for checking FIFO.
2. What could be wrong in the bare metal code which was written for a single byte transfer.
Thank you,
Prasanth K S
Regards
Prasanth