Multiple SPI Instances

Hi,

I'm working on a project where the NRF52840 chip is connected to multiple peripherals (4 of them) through SPI. The hardware has been designed in a way that each peripheral has its separate SPI pins (separate clock and data pins). I'm trying to define an SPI instance for each device, however, I'm facing the following issues with that approach:

1- I used SPI instance 0 with no issues. I used instance 1 for another device and I got this compilation error:

error:  #20: identifier "NRF_DRV_SPI_INSTANCE_1" is undefined

I tried to enable multiple things in the sdk_config.h but none of them worked. Please let me know how to enable Instances1,2,3 properly.

2- I tried to reuse the same instance for 2 peripherals but I got this runtime error:

NRF_ERROR_INVALID_STATE which occurred when calling  "nrfx_spi_init" inside "nrf_drv_spi_init"

3- Is there a better approach you can recommend to talk to 4 devices at the through different SPI?

Regards

Parents
  • Thanks a lot Jared. Here are my responses:

    - On the hardware side, each peripheral has a separate CS pin. I know this is not the ideal design but I need to live with that.

    And for the questions:

    1- Thanks for the info. I'll try that and see if this works.

    2- For this one, I used Instance 0 for example to initialize the spi interface for two peripherals (i.e. I reinitialised the same instance twice for 2 peripherals), which does not work from the description of the error code.

    3- I agree that would be the ideal case. However, I dont think I can change the hardware at the moment. My question was more about how to handle the current hardware from the firmware side. Do you recommend defining a different instance for each peripheral or can I reuse the same instance for multiple peripherals

    Thanks a lot in advance!

  • EAkeila said:

    2- For this one, I used Instance 0 for example to initialize the spi interface for two peripherals (i.e. I reinitialised the same instance twice for 2 peripherals), which does not work from the description of the error code.

    Have you un initialized the driver first by calling nrfx_spim_uninit (nrfx_spim_t const *p_instance)?

    EAkeila said:
    3- I agree that would be the ideal case. However, I dont think I can change the hardware at the moment. My question was more about how to handle the current hardware from the firmware side. Do you recommend defining a different instance for each peripheral or can I reuse the same instance for multiple peripherals

    I don't think it matters much if you don't use them at the same time. The current consumption would effectively be the same. 

  • Have you un initialized the driver first by calling nrfx_spim_uninit (nrfx_spim_t const *p_instance)?

    Thanks Jared. So for using one SPI instance for 2 peripherals, do I need to call "nrfx_spim_uinit" and re-initialise spi every time I need to do an spi transaction on each peripheral?

Reply Children
Related