Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

implement 2 hardware SPI

i want to implement 2 hardware SPI communication in my code. i have one already working. talking with LCD ILI9341. the functions are using spi_write /  nrf_drv_spi_transfer for a single interface.  what do i need to do to add another (4 pin) SPI interface to communicate with accelerometer. do i need to change it to SPI1 and then duplicate everything to SPI2 ?

thanks

Yuval

Parents
  • You do not need to add another 4 pins, you can still use the same 4 pins to communicate with the accelerometer, but you need a new slave select pin for sending the data  to this slave. Please take a look at slave configuration at the wiki

  • i already have another 4 pins connected to the acc chip:
    #define LSM6DS3_MOSI_PIN 12
    #define LSM6DS3_MISO_PIN 13
    #define LSM6DS3_SCK_PIN 14
    #define LSM6DS3_SS_PIN 15

    my question is , does anyone have a code example of using 2 different SPI ?

  • If you are using standard Nordic libraries and so on then you just need to use a new instance and duplicate the code. ie if you are doing something like this:

    APP_ERROR_CHECK(nrf_drv_spi_init(&mAccSpiInstance, &spi_config, acc_spi_event_handler, NULL));
    

    Then all you need to do is duplicate the code - typically in a separate c module - and use a new instance thus:

    #define SPI_INSTANCE  1   // SPI instance index for 2nd SPI
    static const nrf_drv_spi_t mAccSpiInstance = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);
    

    Ensure SPI1 is also enabled in sdk_config.h, of course, assuming you use SPI0 and SPI1.

    As an aside, I recommend your choice of hardware implementation as a physically separate SPI interconnect if you want the best analogue performance as any noise on the SPI lines - when updating the display, for instance - will inject some noise into the accelerometer unless you synchronously run the display interface outside of times when the accelerometer (or other SPI ADC or AFE) is being clocked

Reply
  • If you are using standard Nordic libraries and so on then you just need to use a new instance and duplicate the code. ie if you are doing something like this:

    APP_ERROR_CHECK(nrf_drv_spi_init(&mAccSpiInstance, &spi_config, acc_spi_event_handler, NULL));
    

    Then all you need to do is duplicate the code - typically in a separate c module - and use a new instance thus:

    #define SPI_INSTANCE  1   // SPI instance index for 2nd SPI
    static const nrf_drv_spi_t mAccSpiInstance = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);
    

    Ensure SPI1 is also enabled in sdk_config.h, of course, assuming you use SPI0 and SPI1.

    As an aside, I recommend your choice of hardware implementation as a physically separate SPI interconnect if you want the best analogue performance as any noise on the SPI lines - when updating the display, for instance - will inject some noise into the accelerometer unless you synchronously run the display interface outside of times when the accelerometer (or other SPI ADC or AFE) is being clocked

Children
No Data
Related