SPI on YRDKRX62N

Hello,

I want to perform SPI communication between YRDKRX62N and a slave. SPI0 can communicate with 4 slaves. However, according to the pin definitions in the library and the attached diagram on the Kit, these slave select pins have been specially configured for modules such as Wifi, LCD, Flash, and SD. But these pins are still available on the Kit, so I wonder if I can use these slave select pins for other slaves that I want to communicate with.

  • Fortunately, the Kit I am using does not have a WiFi module, so I can use one SS pin (SSL2A_A) for the slave I want to communicate with. However, I am experiencing issues when using DMA in the SPI protocol on channel 0. I am using the Renesas Peripheral Driver Library, and here is my code snippet:

    //Start my code

    uint8_t master_tx1_data[8] = {0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40};

    R_SPI_Create( 0,
                             PDL_SPI_FULL_DUPLEX | PDL_SPI_MODE_SPI_MASTER | PDL_SPI_PIN_A | PDL_SPI_PIN_SSL2_LOW,
                            PDL_SPI_FRAME_1_1,
                            PDL_NO_DATA,
                            2E6 );

    R_SPI_Command( 0,
                                   0,
                                   PDL_SPI_CLOCK_MODE_0 | PDL_SPI_MSB_FIRST | \
                                   PDL_SPI_ASSERT_SSL2 | PDL_SPI_LENGTH_8,
                                   PDL_NO_DATA);

    R_DMAC_Create(1,                                                                            // channel selection
                                 PDL_DMAC_BLOCK | PDL_DMAC_SOURCE_ADDRESS_PLUS    
                                 | PDL_DMAC_DESTINATION_ADDRESS_FIXED | PDL_DMAC_SIZE_8,
                                 PDL_DMAC_TRIGGER_SPI0_TX,                                                    // trigger selection
                                 master_tx1_data,                                                                               // source start address
                                (uint8_t *)&RSPI0.SPDR,                                                                   // destination start address
                                1,                                                                                                        // transfer count
                                8,                                                                                                        // repeat or block size 
                                PDL_NO_DATA,                                                                                // address offset
                                PDL_NO_DATA,                                                                                // source address extended repeat area
                                PDL_NO_DATA,                                                                                // destination address extended repeat area
                                PDL_NO_FUNC,                                                                               // callback function
                                0 );                                                                                                     // interrupt priority level

    R_DMAC_Control ( 1, PDL_DMAC_ENABLE,  PDL_NO_PTR, 
                                 PDL_NO_PTR, PDL_NO_DATA, 
                                 PDL_NO_DATA, PDL_NO_DATA, 
                                 PDL_NO_DATA,  PDL_NO_DATA );


    R_SPI_Transfer( 0,
                               PDL_SPI_DMAC_TRIGGER_ENABLE,
                               PDL_NO_PTR, //transmit data start address
                               PDL_NO_PTR,
                               PDL_NO_DATA,
                               PDL_NO_FUNC,
                               0 );

    //End

    Help me check why this code is not functioning properly. 

  • Hello John,

    Can you please tell more about what you mean by "not functioning properly"?

    This would be really helpful to understand what exactly happens there.

    Kind regards,

    Sergey

    If this response, or one provided by another user, answers your question, please verify the answer. Thank you!

    Renesas Engineering Community Moderator
    https://community.renesas.com/
    https://academy.renesas.com/
    https://en-support.renesas.com/knowledgeBase/

  • I tried debugging the attached program. I examined the assembly code, and when it reached the line of code "RSPI_Transfer()", the program entered into an infinite loop and couldn't exit.

    This is the SPI0 and DMA register before executing the 'RSPI_Transfer()' line of code.

    This is the SPI0 and DMA register after executing the 'RSPI_Transfer()' line of code.

    I don't know what the problem I'm facing is. Could you help me check where I might have made a mistake?

  • Hello John,

    I've looked though the whole code very carefully and everything looks fine. What is happening after this code? Maybe you need to wait while the operation is completed like it's done in this example: https://www.renesas.com/us/en/document/mat/rx62n-group-rx621-group-renesas-peripheral-driver-library-users-manual-rev112#%5B%7B%22num%22%3A756%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C52%2C757%2C0%5D?

    According to the register states, it seems like the transfer has been completed successfully. I'm only confused with the value 0xE8 of the SPCR register. It means that the receive and transmit interrupts become enabled (https://www.renesas.com/us/en/document/mah/rx62n-group-rx621-group-users-manual-hardware-rev140?r=1054421#G37.1049195) which you seem not to intent to do.

    Did you check if the data is really sent via the SPI pins? According to the registers they should be.

    Kind regards,

    Sergey

    If this response, or one provided by another user, answers your question, please verify the answer. Thank you!

    Renesas Engineering Community Moderator
    https://community.renesas.com/
    https://academy.renesas.com/
    https://en-support.renesas.com/knowledgeBase/

  • I tried adding a print statement for debugging purposes as shown in the image below, but the program couldn't print the value '4'.

    It seems that when executing the 'R_SPI_Transfer()' function, the program falls into an infinite loop. And the attached image shows this loop in the assembly code.

     I examined the assembly code to try to identify the error, and in the assembly code segment where the loop containing the problematic program execution is, I came across the following segment as shown in the image below. I'm not sure if this segment has any impact on the issue I'm facing.

  • Hm... That undefined instruction looks suspicious. Did you try to do the step-by-step debugging of the R_SPI_Transfer function to find out after which exact function it hangs?

    Also try to implement the SPI transfer without the DMA to see if it works fine, thus we will know in what part the problem is - DMA or RSPI.

    Kind regards,

    Sergey

    If this response, or one provided by another user, answers your question, please verify the answer. Thank you!

    Renesas Engineering Community Moderator
    https://community.renesas.com/
    https://academy.renesas.com/
    https://en-support.renesas.com/knowledgeBase/

  • Thank you for your suggestion. I detected an error when I use SPI communication with DMA using 8 or 16-bit data. My program fails to run in these cases, but when I switch to 32-bit data, it finally runs. However, I have read the hardware manual and couldn't find any information about this issue. Do you know why it is necessary to use 32-bit data for SPI communication with DMA?

  • Hello John,

    Probably, you can't do this:

    (uint8_t *)&RSPI0.SPDR,                                                                   // destination start address

    The SPDR register itself is 32 bit, so you need to use 32-bit width to transfer it.

    Kind regards,

    Sergey

    If this response, or one provided by another user, answers your question, please verify the answer. Thank you!

    Renesas Engineering Community Moderator
    https://community.renesas.com/
    https://academy.renesas.com/
    https://en-support.renesas.com/knowledgeBase/