AnsweredAssumed Answered

SPI as slave interface hanging after 2 to 3 minutes.

Question asked by vijith G on Jul 23, 2019
Latest reply on Jul 31, 2019 by Alexis Andalon

Hi

 

I am using  MKE02Z32VFM4 microcontroller for the development of project. I have to use spi interface as master  for accessing data from an ADC. Another spi as slave to receive commands from the master. Currently I am facing an issue i.e. After 2 or 3 minutes slave spi getting hanged on SPI_IsSPRF. My configuration for SPI 1

SPI_ConfigType sSPIConfig1 = {0};

/* initialize SPI1 as slave */
  
    sSPIConfig1.u32BitRate                      = 1000000;
    sSPIConfig1.u32BusClkHz                     = BUS_CLK_HZ;
    sSPIConfig1.sSettings.bShiftLSBFirst        = 0;
    sSPIConfig1.sSettings.bMasterMode           = 0;
    sSPIConfig1.sSettings.bClkPolarityLow       = 1;
    sSPIConfig1.sSettings.bClkPhase1            = 1;
    sSPIConfig1.sSettings.bMasterAutoDriveSS    = 0;
    sSPIConfig1.sSettings.bIntEn                = 1;
    sSPIConfig1.sSettings.bModuleEn             = 1;
    sSPIConfig1.sSettings.bMatchIntEn           = 0; 
    //SPI_ModfEnable(SPI1);
   // SPI_SSOutputDisable(SPI1);
    SPI_Init(SPI1, &sSPIConfig1);
    SPI_SetCallback(SPI1,SPI_Task);

 

Master SPI spi0 works fine. But slaves causes problem for me.

 

in interrupt service routine  called this function.

 

ResultType SPI_Transfer_Wait(SPI_Type *pSPI, SPI_WidthType *pRdBuff, SPI_WidthType *pWrBuff,uint32 uiLength)
{
    ResultType err = SPI_ERR_SUCCESS;
    uint32_t  i;
    if(!uiLength)
    {
        return (err);
    }
   
    for(i = 0; i < uiLength; i++)
    {  
     while(!SPI_IsSPTEF(pSPI))
        {
          if(iCount>=1)
          {
            iCount=0;
            goto SPS;
          }
        }
        SPI_WriteDataReg(pSPI,pWrBuff[i]);
SPS:       
      while(!SPI_IsSPRF(pSPI))
        {
          if(iCount>=1)
          {
             iCount=0;
             goto SOS;
          }
        }  
        pRdBuff[i] = SPI_ReadDataReg(pSPI);   
SOS:            
    }
    
   
    return (err);       
}

 

Please let me know what change I have to make.

Outcomes