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.

RM44L920: Problems when using spiSendAndGetData() and spiEndNotification()

Expert 1060 points
Part Number: RM44L920

Hi TI experts,

I have a question about SPI. I have two RM44L920 board and connected each other for SPI communicaton.

The SPI communication between Master <-> Slave is well.

But there is a problem using break point and function call sequence.

A. break point problem

The purpose of this question is to know exact time when SPI received the data from Master. because spiEndNotification() recalls 2 times during execution.

I use spiTransmitAndReceiveData() on Master and spiSendAndGetData() on Slave.

This is the slave code for reference.

1616.sys_main.c

 7345.notification.c

if I use break point at spiEndNotification(), the if statement condition can be passed. and doneSPI3=0; is set.

//if(spi==spiREG3 && ((spiREG3->FLG & 0x00000100U) == 0x00000100U))

// if((spiREG3->INT0 & 0x00000100U) == 0x00000100U)
   // if((spiREG3->FLG & 0x00000100U) == 0x00000100U)

but if I release break point, the doneSPI3=0; doesn't seem to executed.

it is stopped  when I click "suspend" on CCS. the while(doneSPI3); in main function is executing.

Even though the RX Buffer successfully received the data, it doesn't proceed the rest "printf" in main(),

If I eliminate the If statement, it works well.

Is there any problem to use this if statement in spiEndNotification()? How should I do to know when the data received?

2. mibspi3HighInterruptLevel(void) calling sequence.

I connected all the vector into FIQ and mibspi3HighInterruptLevel() is executed.

I just track the calling sequence but there's something I don't understand.

This is the first execution of spiEndNotification() break point in if statement.

and the if statement is true and go to doneSPI3=0;

But it is returned to 964 line which case of 0x28U /* Transmit Buffer Empty Interrupt*/

I expect case of 0x24U /*receive Buffer Full Interrupt*/ becasue spiEndNotification() if statement is passed.

then it stops spiEndNotification() with different reg value.


And it doesn't go into if statement which already executed.

but it returns to 0x24U /*receive buffer full interrupt*/


What I don't understand is this sequence.

I just exepect this sequence

A. case 0x24 in spi.c calls spiEndNotifiication with proper register setting

B. if state ( true) set the doneSPI3 in spiEndNotificaton

C. case 0x28 in spi.c calls spiEndNotifiication

D. if state ( false ) in spiEndNotificaton

 

But actual sequence is

C -> B -> A ->D

Even at "B" stages already seems to filled all the RX received data.

 

Please advice me for better understanding.

 

Best Regards,

Jay.

  • Hello Jay,

    Indeed that is strange behavior. It appears both the receive buffer full and transmit buffer empty interrupts are set in the FLG register (0x00000300 in your first screenshot) but I would have expected the FLG register to be 0x000001000 after servicing the transmit buffer empty interrupt. Let me try to reproduce this on my setup and get back to you.

    There are two interrupt lines, line 0 and 1 - if you separate the receive buffer full and transmit buffer empty interrupts onto different interrupt lines, do you still observe the same behavior?

    Regards,
    Sahin

  • 0815.SPI_Slave.zip

    Hi Sahin,

    Thank you for the guidance. Even though I separate the interrupt line, similar behavior observed.

    I attached simplified my slave project.

    And some capture file and description with my question.

    5224.SPI.pptx

    Please reveiw and give me some advice.

    I will try to send and receive the data via SCI not to use JTAG.

    Best Regards,

    Jay.

  • Hi Sahin,

    Execute without JTAG doesn't works. there's different result with/without break point at [if(flag == 0x00000100U)]

    I really don't understand why this flag doen't pass during execution even the SPI send the data well.

    #pragma WEAK(spiEndNotification)
    void spiEndNotification(spiBASE_t *spi)
    {
        flag = spi->FLG & 0x00000100U;
        if(flag == 0x00000100U)
            doneSPI3=0;
    }

    What else do I can check for this strange result?

    Best Regards,

    Jay.

  • Hi Jay,

    The same behavior is observed with and without a breakpoint, so we can rule that variable out, correct?

    Can you set a breakpoint in spiEndNotification and check the values of flag and spi->FLG in Variables/Expressions window and compare them between the working and non-working case? What do you observe?

    Regards,
    Sahin

  • Hi Sahin,

    I attached the all the sequence with the capture. please refer to the ppt.

    Actually what I want to know is the timing when slave RX buffer received.

    But (1.) the strange function call sequence make me confuse and (2.) I don't understand why spi->FLG & 0x00000100U can not recognize.

    If I just treat the notification as a alarm which shows the RX buf full without checking, I can use it.

    But I really do not sure whether it is right way.

    Best Regards,

    jay.

    5618.SPI.pptx

  • Hi Jay,

    Thank you for the detailed write-up. This sounds like it could be a timing issue. 

    If you replace the if() statement in the ISR with a while() loop, do you still observe it hanging or does doneSPI3 get cleared every time?

    while((spiREG1->FLG & 0x00000100U) != 0x00000100U);

    If it's working as expected with the above code, I would suspect it's a timing issue. 

    Could you please try this experiment and let me know?

    Regards,
    Sahin

  • hi Sahin,

    it hangs at your suggested code at ISR when I suspend the CCS.

    please refer to the picture.

    Best Regards,

    Jay.

  • Hi Jay,

    I'm sorry for the delay. I will try to reproduce this on my end and get back to you.

    Regards,
    Sahin

  • Hi Jay,

    I have not been able to get this up and running on my setup yet, but have you taken a look at the thread below? There is a working example project using spi_SendandGetData() provided in that thread that I think would be of interest to you.

    https://e2e.ti.com/support/microcontrollers/hercules/f/312/t/300434

    Please take a look and let me know.

    Regards,
    Sahin