Hi,
I am facing an issue with LPSPI in S32K144 while sending and receiving 8 bytes of data in one call. I am not using driver that is provided with SDK.
In Master I have tried with 8 bits frame and 32 bits frame but I am not able to successfully receive data on slave side. sometimes it successfully returns one call of transmission but then stuck on the second call for ever.
Here are configurations and transmit function for master:
/************************************************/ void lpspi_init() /************************************************/ { LPSPIx_CR = 0x00000000UL; /* Disable module for configuration */ LPSPIx_IER = 0x00000000UL; /* Interrupts not used */ //LPSPIx_DER = 0x00000003UL; /* receive DMA used */ LPSPIx_CFGR0 = 0x00000000UL; /* Defaults: */ LPSPIx_CFGR1 = 0x00000001UL; /* MASTER=1: Master mode */ LPSPIx_CCR = 0x00000000UL; /* default values */ LPSPIx_TCR = 0x4080001FUL; /* LSB first, Data on leading edge, frame size 32 */ LPSPIx_FCR = 0x00000003UL; /* default values */ LPSPIx_CR = 0x00000009UL; /* Enable module for operation */ /* DBGEN=1: module enabled in debug mode */ /* DOZEN=0: module enabled in Doze mode */ /* RST=0: Master logic not reset */ /* MEN=1: Module is enabled */ }
/*********************************************/ bool lpspi_sendData(uint8 * pData) /*********************************************/ { bool retval = false; while(0 == (LPSPIx_SR & (uint32)0x01)); /* Wait for Tx FIFO available */ // LPSPIx_TDR = pData[0]; // LPSPIx_TDR = pData[1]; // LPSPIx_TDR = pData[2]; // LPSPIx_TDR = pData[3]; // LPSPIx_TDR = pData[4]; // LPSPIx_TDR = pData[5]; // LPSPIx_TDR = pData[6]; // LPSPIx_TDR = pData[7]; LPSPIx_TDR = (uint32)(pData[3]<<24|pData[2]<<16|pData[1]<<8|pData[0]); LPSPIx_TDR = (uint32)(pData[7]<<24|pData[6]<<16|pData[5]<<8|pData[4]); LPSPIx_SR |= LPSPI_SR_TDF_MASK; /* Clear TDF flag */ retval = true; return retval; }
Configurations and Receive function for slave:
void lpspi_init() { LPSPIx_CR = 0x00000000UL; /* Disable module for configuration */ LPSPIx_IER = 0x00000000UL; /* Interrupts not used */ LPSPIx_DER = 0x00000003UL; /* receive DMA used */ LPSPIx_CFGR0 = 0x00000000UL; /* Defaults: */ LPSPIx_CFGR1 = 0x00000000UL; /* default values */ LPSPIx_CCR = 0x00000000UL; /* default values */ LPSPIx_TCR = 0x40800007UL; /* LSB first, Data on leading edge, frame size 8 */ LPSPIx_FCR = 0x00020000UL; /* default values */ LPSPIx_CR = 0x00000001UL; /* MEN=1: Module is enabled */ }
void ll_rx rx_buff_struct* rx_buffer) { /* Check SPI state. Read receive FIFO. */ if((LPSPIx_SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT) { /* Receive FIFO is not empty */ /* Read received data */ rx_buffer->frame.data[0] = LPSPIx_RDR; rx_buffer->frame.data[1] = LPSPIx_RDR; rx_buffer->frame.data[2] = LPSPIx_RDR; rx_buffer->frame.data[3] = LPSPIx_RDR; rx_buffer->frame.data[4] = LPSPIx_RDR; rx_buffer->frame.data[5] = LPSPIx_RDR; rx_buffer->frame.data[6] = LPSPIx_RDR; rx_buffer->frame.data[7] = LPSPIx_RDR; LPSPIx_SR = (((uint32)(((uint32)(0))<<LPSPI_SR_RDF_SHIFT))&LPSPI_SR_RDF_MASK); /* Clear RDF flag */ rx_buffer->received = true; rx_buffer->frame.atyp = Physical; } else { rx_buffer->received = false; } }
Master just stuck at "while(0 == (LPSPIx_SR & (uint32)0x01));" and doesn't move forward. But if I am debugging and step over it it will then move forward. In normal run it just stuck here.
Here I am not receiving anything in Master and there is no transmission in Slave.
Can you please check and see what is it that I am not doing right. Your quick response to this issue will be highly appreciated.
Hi,
I am facing issue with LPSPI in s32k144 while sending and receiving 5 bytes of data. I am using driver initialization provided by SDK but for transmission and reception I am not using driver code. I am able to transmit data but while reading the RDF flag is not getting set. I have attached the snapshots please check where is the mistake
Hi,
Thanks for the reply. I can not use SDK; I have to use my own codes for this.
Anyway I have figured out the solution. Like I said I am not receiving anything on Master so master's RXFIFO was getting full and there was an RX error in Status register of LPSPI. So I started a dummy read so RX FIFO doesn't get full and there is no RX error. Now things are working fine.
P.S: I don't think my use case would have been handled by SDK as well as I wasn't executing RX functions of LPSPI.
Regards,
Muhammad Imran Afzal
I meet the same problem !!!CAN you explain your solution with more details, HOW to START a dummy read ?THANK YOU !
Hi all,
muhammadimranafzal: you can use RXMSK bitfield to disable receiving side.
935348277@qq.com: Please create another post for your problem. CAN and LPSPI are totally different and you should provide more details about your usecase.
Best regards,
Razvan
Hi,
Sorry for the late response.
I don't see exactly the problem in your source code, but why you don't use SDK for this MCU?
Best regards,
Razvan