This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RM57L843: Problem is that the data is lost in the case of two spi simultaneous interrupt

Part Number: RM57L843

The system block is below:

The problem is that when the SPI2 and SPI3 of the RM57L843 receive data from RM42 at the same time, one byte is lost.

In order to facilitate observation,  the gio pin state is changed in the start and end interrtup of SPI2 and SPI3.

void vSpi2IrqHandle(void)
{
    uint32 flags = (spiREG2->FLG & 0x0000FFFFU) & (~spiREG2->LVL & 0x035FU);
    uint32 vec = spiREG2->INTVECT0;
    
    ( *( volatile uint32 * )0xFFF7B854UL ) &= ~( 1 << 0 ); // set GPI PIN low
    
    switch(vec)
    {
        case 0x24U: /* Receive Buffer Full Interrupt */
        {
            spi2_temp0 = (uint8)spiREG2->BUF;
                                            
            my_printf("1 %d\r\n", spi2_temp0); // print to the PC through SCI
            
            if(spi2_flg == 0) // In order to remove the first set of data
            {
                spi2_flg = 1;
            }
            else
            {
                if((spi2_last == 5) && (spi2_temp0 == 1)) // the host data send 1 2 3 4 5 In order。 
                {
                
                }
                else if((spi2_temp0-spi2_last)==1) // To determine whether byte is lost
                {
                
                }
                else
                {
                    my_printf("error2\r\n");
                    while(1); // if lost then stop
                }
                
            }
            spi2_last = spi2_temp0;
                     
            break;
        }

        case 0x28U: /* Transmit Buffer Empty Interrupt */
        {
            break;
        }
        
        case 0x26U:/*data over Run*/
        {
            my_printf("data over run !\r\n");
            break;
        }        

        default: /* Clear Flags and return  */
            spiREG2->FLG = 0xFFFF;
            break;
    }
    
    ( *( volatile uint32 * )0xFFF7B854UL ) |=  ( 1 << 0 ); // set gio pin High
}
void vSpi3IrqHandle(void)
{
    uint32 flags = (spiREG3->FLG & 0x0000FFFFU) & (~spiREG3->LVL & 0x035FU);
    uint32 vec = spiREG3->INTVECT0;
    
    ( *( volatile uint32 * )0xFFF7B854UL ) &= ~( 1 << 5 ); // set gio pin low
    
   
    switch(vec)
    {
        case 0x24U: /* Receive Buffer Full Interrupt */
        {
            spi3_temp0 = (uint8)spiREG3->BUF;
            
            my_printf("2 %d\r\n", spi3_temp0);

            if(spi3_flg == 0)
            {
                spi3_flg = 1;
            }
            else
            {
                if((spi3_last == 5) && (spi3_temp0 == 1))
                {
                
                }
                else if((spi3_temp0-spi3_last)==1)
                {
                
                }
                else
                {
                    my_printf("error3\r\n");
                    while(1);
                }
                
            }
            spi3_last = spi3_temp0;           
            break;
        }

        case 0x28U: /* Transmit Buffer Empty Interrupt */
        {
            spiREG3->FLG &= (~(1<<9));
            break;
        }
        
        case 0x26U:/*data over Run*/
        {
            my_printf("data over run !\r\n");
            spiREG3->FLG &= (~(1<<6));
            break;
        }

        default: /* Clear Flags and return  */
            spiREG3->FLG = 0xFFFF;
            break;
    }    
    
    ( *( volatile uint32 * )0xFFF7B854UL ) |=  ( 1 << 5 ); // set gio pin high

}

oscilloscope wave:


the serial data :

as the code shown above , By observing the oscilloscope and serial data, when the data is lost , the wave just to meet. 

I tried a lot of ways, but still did not solve the problem,

Who knows where the problem may be?

  • Hello User,

    I am currently reviewing your post and will get back with you with my observations soon.
  • Thank you for your reply. 

    At first, I doubt that the frequency between the two byte is too fast when the data send by spi2 and spi3 at the same time. this causes the data to be overrun.  like below:

    so i reduces the frequency of transmission between two bytes, for 50us two bytes but the the problem still exists. 

    So I suspect that the data is lost because the SPI interruption is suspended temporarily.......

  • Hello User,

    Have you tried minimizing the time in the interrupt handler? i.e., you currently perform a printf function within the inerrupt, the time to perform this task is significant especially considering the normal UART baud rates vs. normal SPI baudrates in the megabit range so, for sure if you do not re-enable interrupts at the beginning of the handler, you wll have overrun scenarios. My recommendation is to, at a minimum, copy the received data to a buffer and handle the print function outside the ISR routines by setting a flag indicating SPI data received. Other option is to use DMA to automatically transfer data into a buffer location for printing via SCI. You may also consider use of the MiBSPI so that receive interrupts only happen when transfer groups are full to reduce the CPU loading.
  • Hello TI support:

               The Demo written  is just for test, because my project always lost data when two interrupt of SPI happen.  The real project has no printf just some swich-case Judge sentences,and i think that there are no so many time in interrupt. what is more, if I comment sentence “ my_printf("1 %d\r\n", spi2_temp0);  ” and " my_printf("2 %d\r\n", spi3_temp0); ", The program can alse still jump to " my_printf("error2\r\n"); " or " my_printf("error3\r\n"); " , that is to say , data is lost too. 

               I need to get one byte then judge one byte so the DMA and MibSPI are not suitable here.  and i could not find receive interrutp in mibspi in the datasheet.

               After a few days I will test with another CPU with the same code.  i doubt if the RM57 CPU has bug in SPI. 

  • Would it be possible for you to zip up your project and post it along with details regarding the frequency that spi messages are delivered for both SPI2 and SPI3?

    Based on your diagram, this is a 3 MCU communication scheme. Do you have code/projects for all MCUs that we can setup in our lab to debug the application. Basically anything that you can provide that we can use to recreate your setup and troubleshoot it.
  • 8228.DEMO7_ZD_CheckLostData.zip

    hello TI support:

    Thank you for your reply!

    This project is used to test SPI communication

    Two RM42 chips use SPI2 port com communicate with RM57 SPI2 and SPI3 port.
    The frequency of SPI is 25000Kbits/s
    The frequency of RM57 SCI is 900Kbits/s
    The interval between two bytes of SPI is 100us.
    The IDE is IAR7406


    The two RM42 send 1 2 3 4 5 num to the RM57 through SPI. then RM57 judge whether the difference between the two received numbers is 1 except num 5 and 1.