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

Multiple instances of SPI

Hi all,

Provided the nRF52840 board implements up to 4 SPI, I would like to use at least 2 of them simultaneously.
I need to do it like this because I need one of them to be running during a certain amount of time constantly and the other one only sporadically. Both must be relatively precise, thus one running in "background" using a PPI channel would be the best solution. Sometimes the both could be active at the same time, thus, cannot share the bus.

SPI 1 will be triggered by a timer using PPI and constantly upload the read buffer.(is a callback function mandatory?)

SPI 2 I would like to trigger only after an ESB command is received. Ideally I would like the ESB to just trigger another PPI channel between a timer and SPI, but it's ok if the microcontroller needs to take active action here.

Because I want to use a PPI channel, the idea of sharing the bus and manually triggering the SS pin is difficult to implement. I'd rather use 8 pins of the board instead.

The main issue is that I can only implement SPI 1, and SPI 2 never starts. I tried using two PPI channels, triggering SPI 1 and SPI 2 with the same timer, and triggering SPI 2 with the end transfer of SPI 1 event, but to no result.

I have enabled # define SPI1_ENABLED 1  and #define SPI2_ENABLED 1.

There are several posts about this but the solutions are no longer applicable because they correspond to a different SDK or reference to dead links. All in all I could not find a suitable answer in the infocenter.

Bests,

Parents
  • Hi 

    Are any of the SDK drivers returning any error codes, either during initialization or when you try to run SPI communication?

    Which SPI driver are you using in the application?

    Where you able to get SPI1 to work correctly on it's own, including the communication with the sensor?

    Also, if you have a link to any old cases that you feel are relevant to your issue feel free to share them. 

    Best regards
    Torbjørn

  • Hi, thanks for the answer.

    1) According to the SEGGER debugger, the error comes from the second time I call the initialization method: 

    ret = nrf_drv_spi_init(&spi2, &spi_config2, spi_event_handler2, NULL); 

    It never returns from this method. I do not know how to export the debugger log, so I will show the snippet:

    2) I am using the "SPI Master Driver" (nrf_drv_spi), because the PPI examples used it too. I would have used the "SPI Driver" (nrfx_spi) but I couldn't make it run with PPI.

    3) Yes, I was able to make the SPI 1 work correctly. I just analyzed the CLK and MOSI signals and they were correct.

    If the error has something to do with the legacy driver I am using, I can try using the newer drivers but I would require an example how to use it with the PPI channel.

    err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel1);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel1,
                                          nrf_drv_timer_event_address_get(&TIMER_RECORDING,
                                                                          NRF_TIMER_EVENT_COMPARE0),
                                          nrf_drv_spi_start_task_get(&spi));
    APP_ERROR_CHECK(err_code);

    Bests,
    Fran89

Reply
  • Hi, thanks for the answer.

    1) According to the SEGGER debugger, the error comes from the second time I call the initialization method: 

    ret = nrf_drv_spi_init(&spi2, &spi_config2, spi_event_handler2, NULL); 

    It never returns from this method. I do not know how to export the debugger log, so I will show the snippet:

    2) I am using the "SPI Master Driver" (nrf_drv_spi), because the PPI examples used it too. I would have used the "SPI Driver" (nrfx_spi) but I couldn't make it run with PPI.

    3) Yes, I was able to make the SPI 1 work correctly. I just analyzed the CLK and MOSI signals and they were correct.

    If the error has something to do with the legacy driver I am using, I can try using the newer drivers but I would require an example how to use it with the PPI channel.

    err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel1);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel1,
                                          nrf_drv_timer_event_address_get(&TIMER_RECORDING,
                                                                          NRF_TIMER_EVENT_COMPARE0),
                                          nrf_drv_spi_start_task_get(&spi));
    APP_ERROR_CHECK(err_code);

    Bests,
    Fran89

Children
No Data
Related