AnsweredAssumed Answered

SPI data delay problem

Question asked by Elango M on Oct 18, 2018
Latest reply on Oct 18, 2018 by Kerry Zhou

Hi,

   I am using SPI0 (interrupt based) on the KEA128 MCU. I am trying to transmit 4 bytes of data in buffer to the slave device using SPI mode 0. There are delays between each byte that are being transmitted. The attached image shows my SPI transmission captured using a Digital Oscilloscope; I have captured only the SlaveSelect and Clock waveforms. The MCU is running at 48 MHz with SPI of 12 MHz. I used KEAZ128 SDK for SPI.

 

Initialization:

 

    SIM_PINSEL0  |= SIM_SCGC_SPI0_MASK;

    SPI_ConfigType sSPIConfig = {{0}};

    sSPIConfig.u32BitRate = 12000000;
    sSPIConfig.u32BusClkHz = 24000000;
    sSPIConfig.sSettings.bModuleEn             = 1;
    sSPIConfig.sSettings.bMasterMode           = 1;
    sSPIConfig.sSettings.bClkPhase1            = 0;
    sSPIConfig.sSettings.bClkPolarityLow       = 0;
    sSPIConfig.sSettings.bMasterAutoDriveSS    = 1;
    sSPIConfig.sSettings.bTxIntEn               = 1;
    sSPIConfig.sSettings.bIntEn                   = 1;
    SPI_SetCallback(SPI0,SPI0_ISR);
    SPI_Init(SPI0, &sSPIConfig);

 

ISR:

 

volatile uint8_t index = 0;

void SPI0_ISR()
{
    (void)SPI0_S;
    if ((SPI0_S & SPI_S_SPTEF_MASK))         // Check Tx buffer staus flag@@@ is empty
    {
            if( index == 4)
            {

                index  = 0;
                SPI0_C1 &=~ SPI_C1_SPTIE_MASK;      
            }
            else
            {
                SPI0_D = tx_buffer[index++];
            }
    }
}

 

Main:

 

I initialized SPI then I started the following:

 

   volatile uint8_t tx_buffer[4] = {0};

   tx_buffer[0] = 0x12;
   tx_buffer[1] = 0x10;
   tx_buffer[2] = 0x11;
   tx_buffer[3] = 0x15

   SPI0_C1 &=~ SPI_C1_SPIE_MASK ;       // Disable Receiver

   SPI0_C1 |= SPI_C1_SPTIE_MASK ;         // Enable only transmitter interrupt

   while(1);

 

The Result of the above program is attached below.The Blue coloured waveform is the SlaveSelect and the Yellow is the SPI Clock Pulses. As you see the SPI for transmitting 32 bit should be (1/(12 Mhz)) * 32 Bit  =  3 u-sec(microseconds), but the actual time taken to transmit is 10 u-sec as seen with the Oscilloscope . The maximum observed delay between bytes is  2.3 u-sec. In my program it is processing only SPI Interrupt as I hold the processor (after enabling interrupt). I am not running any timer. Please help me to resolve delay issue between bytes and also overall time.

 

NXP-Community ExpertsMonica Arvizupavel.krenek

Attachments

Outcomes