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
  • Hi,

    The hardware has been designed in a way that each peripheral has its separate SPI pins (separate clock and data pins).

    But not separate CS pins? 

    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.

    You need to enable corresponding nrfx define in sdk_config.h:

    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"

    The driver will return this when it has already been initialized. What do you mean using same instance for 2 peripherals?

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

    You can have one SPIM for multiple slaves by connecting them on the same bus, but you have to use separate CS for each slave. There is possibility that this would decrease the maximum frequency due to the increased line capacitance, but I think it should be ok if you set the GPIO to high drive. Either way you would have to test and see if it works or not.

    regards

    Jared 

Reply
  • Hi,

    The hardware has been designed in a way that each peripheral has its separate SPI pins (separate clock and data pins).

    But not separate CS pins? 

    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.

    You need to enable corresponding nrfx define in sdk_config.h:

    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"

    The driver will return this when it has already been initialized. What do you mean using same instance for 2 peripherals?

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

    You can have one SPIM for multiple slaves by connecting them on the same bus, but you have to use separate CS for each slave. There is possibility that this would decrease the maximum frequency due to the increased line capacitance, but I think it should be ok if you set the GPIO to high drive. Either way you would have to test and see if it works or not.

    regards

    Jared 

Children
No Data