OnBlockReceived is not called when using SPImaster LDD

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

OnBlockReceived is not called when using SPImaster LDD

547 Views
brianherrold
Contributor I

I am evaluating the Kinetis S9KEAZ128 micro for a design. I am using the FRDM board without modification. I am using KDS v3.2 with Processor Expert to generate code.

When I use the SPImaster_LDD component, I am able to send any amount of SPI data bytes without a problem. I am using interrupts. When I attempt to receive spi data, following the example found in the "help with this component", the OnBlockReceived event never occurs. When I stop execution and look at my data structure, it is always filled with n-1 of the bytes transmitted with the last byte never being populated regardless of the length of data sent.

I am not able to post my full code but a simplified version of it is given below:

(main.c)

   SPI0ptr = SM2_Init(NULL);

    uint16_t Local_SPI_Timeout = 0xFFFF;
    LDD_TError Local_SPI0_Error;

    // Local TX/RX Buffers
    uint8_t LocalTX[4];
    uint8_t LocalRX[4];

    LocalTX[0] = 0x55;
    LocalTX[1] = 0xaa;
    LocalTX[2] = 0xbe;
    LocalTX[3] = 0xef;


    LocalRX[0] = 0;
    LocalRX[1] = 0;
    LocalRX[2] = 0;
    LocalRX[3] = 0;


    // Set the GPIO Bit low as a "manual" CS line.
    GPIOA_PCOR |= 1<<28; 

    Local_SPI0_Error = SM2_ReceiveBlock(SPI0ptr, LocalRX, 4);

    // Send the SPI data
    Local_SPI0_Error = SM2_SendBlock(SPI0ptr , LocalTX, 4);

    // Set the GPIO Bit high as a "manual" CS line.
    GPIOA_PSOR |= 1<<28;


    while (!SPI0_DataReceivedFlag && (Local_SPI_Timeout > 0))
    {
        //Local_SPI_Timeout--;
    }

(Events.c)

void SM2_OnBlockReceived(LDD_TUserData *UserDataPtr)
{
    SPI0_DataReceivedFlag = TRUE;
}

I tie MISO and MOSI together on the FRDM board to test. I would expect the code to execute, OnBlockReceieved to be called, SPI0_DataReceivedFlag to be set to 1, and LocalTX and LocalRX to be equal.

What happens is that OnBlockReceieved is never called (breakpoint never reached), SPI0_DataReceivedFlag remains zero, and LocalRX[0] = 55, LocalRX[1] = aa, LocalRX[2] = be, LocalRX[3] = 00. I have verified with a scope that the 4 TX bytes are being transmitted correctly with  the clocks and CS. This pattern occurs for any length of data. If I set the TX and RX size to 10, 10 bytes will send successfully (verified by scope) and the LocalRX array will be filled with the first 9 and the 10th still set to zero.

I would appreciate any suggestions.

Tags (1)
0 Kudos
2 Replies

410 Views
brianherrold
Contributor I

Thank you for your suggestion. That doesn't appear to help.

In desperation, I was trying almost every combination of settings and found that the problem only happens for the .25 us clock period (what I happened to be using). The component functions correctly as described for any clock rate other than .25us Currently I'm running it faster at .083us period and it works fine. Same for slower rates. I made no other changes to my code. Just changed the clock config in PE.

I am still interested in understanding why this is the case if anyone has any insight.

Capture.PNG

410 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Brian,

Sorry for the late reply!

Please try to call SM2_SendBlock first then call  SM2_ReceiveBlock.

// Send the SPI data
Local_SPI0_Error = SM2_SendBlock(SPI0ptr , LocalTX, 4);

// Receive the SPI data

Local_SPI0_Error = SM2_ReceiveBlock(SPI0ptr, LocalRX, 4);

Best Regards,

Robin

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos