This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52840 as SPI slave

Hello, guys!

We are using nRF52840 with SDK 17.2. In our system, there is a need to configure nRf52840 as SPI slave device and connect it to some other MCU. Naturally, our starting point was SPIS example.

We were able to properly receive SPI data packet on nRF52840 side when using SPIS example. The second step was to import SPIS example into our project that uses SoftDevice (among the other things).

Here comes the trouble... when we included SPIS example in our environment, SPI RX buffer (m_rx_buf) contains 0xFF instead of real data bytes. We checked the SPI lines with the logic analyzer and it seems that, on physical level everything is OK, the bytes are properly sent from the SPI master side.

The number of bytes sent from SPI master and received on SPI slave side (nRF52840) is correct, as you can see below.

<info> mercury_spi: Transfer completed! 9 Bytes received
<info> mercury_spi:  FF FF FF FF FF FF FF FF|........
<info> mercury_spi:  FF 00 00 00 00 00 00 00|........
<info> mercury_spi:  00                     |.      
<info> mercury_spi:  01 00 00 00 00 00 00 00|........
<info> mercury_spi:  00 00 00 00 00 00 00 00|........
<info> mercury_spi: SPI RX/TX buffers set!

Do you have any idea what we are missing here? Why our m_rx_buf buffer contains 0xFF on the place of real data?

Thanks in advance for your time and efforts.

Sincerely,

Bojan

Parents
  • I found the issue, guys.

    The problem was in the way I defined GPIOs for SPI connection. I initially did it through #define pre-processor directives:

    #define SPIS_CS_PIN     31 // P0.31
    #define SPIS_MISO_PIN   30 // P0.30
    #define SPIS_MOSI_PIN   29 // P0.29
    #define SPIS_SCK_PIN    28 // P0.28

    However, this was not enough. It was needed to explicitly cast to uint_32t:

    #define SPIS_CS_PIN     ((uint32_t)31) // P0.31
    #define SPIS_MISO_PIN   ((uint32_t)30) // P0.30
    #define SPIS_MOSI_PIN   ((uint32_t)29) // P0.29
    #define SPIS_SCK_PIN    ((uint32_t)28) // P0.28

    I'm sharing this experience with the hope to save somebody's time in the future.

    Cheers!

    Bojan.

Reply
  • I found the issue, guys.

    The problem was in the way I defined GPIOs for SPI connection. I initially did it through #define pre-processor directives:

    #define SPIS_CS_PIN     31 // P0.31
    #define SPIS_MISO_PIN   30 // P0.30
    #define SPIS_MOSI_PIN   29 // P0.29
    #define SPIS_SCK_PIN    28 // P0.28

    However, this was not enough. It was needed to explicitly cast to uint_32t:

    #define SPIS_CS_PIN     ((uint32_t)31) // P0.31
    #define SPIS_MISO_PIN   ((uint32_t)30) // P0.30
    #define SPIS_MOSI_PIN   ((uint32_t)29) // P0.29
    #define SPIS_SCK_PIN    ((uint32_t)28) // P0.28

    I'm sharing this experience with the hope to save somebody's time in the future.

    Cheers!

    Bojan.

Children
No Data
Related