AnsweredAssumed Answered

LPSPI issue in S32K144 while receiving and sending 8 bytes

Question asked by muhammadimranafzal on Oct 30, 2017
Latest reply on Nov 23, 2017 by muhammadimranafzal

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.

 

Razvan-nicolae Tilimpea

Outcomes