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

2 SPI devices nordic nRF52382

Hi All, 

I am using nRF52382 and sdk 15.0. I have two SPI devices using separate pins. They work just fine separately, when I try to enable two instances I get compilation errors

Device 1 setup (separate):

#define SPI_INSTANCE 1 /**< SPI instance index. */
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); /**< SPI instance. */

nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.ss_pin = 11;
spi_config.miso_pin = 17;
spi_config.mosi_pin = 12;
spi_config.sck_pin = 13;
spi_config.frequency = NRF_DRV_SPI_FREQ_8M; 
spi_config.mode = NRF_DRV_SPI_MODE_1; //MODE 0 for flash 1 for DAC 
spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;

APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));

Device 2 setup (separate):

#define SPI_INSTANCE 1 /**< SPI instance index. */
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); /**< SPI instance. */

nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.ss_pin = 29;//
spi_config.miso_pin = 30;//
spi_config.mosi_pin = 27;//
spi_config.sck_pin = 25;//
spi_config.frequency = NRF_DRV_SPI_FREQ_8M; 
spi_config.mode = NRF_DRV_SPI_MODE_0; //MODE 0 for flash 1 for DAC 
spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;

APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));

Can anyone please guide me how should I enable both devices to work simultaneously? 

Parents
  • Change the second instance to (eg) 2; the instance selects the SPI peripheral 0, 1 or 2 and you are using 2 of these. You might have to also change the sdk_config.h to ensure that the SPI2 is enabled otherwise there will be build errors. Search for "_ENABLED 1" to locate the settings which enabled all peripherals and in particular SPI 1 (ie. instance 1) then find SPI2 and enable likewise.

  • I am trying to use instances 1 and 2 as you suggested.
    In the main file: 

    #define SPI_INSTANCE  1 /**< SPI instance index. */
    static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */
    
        nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
        spi_config.ss_pin   = 11;//29;//
        spi_config.miso_pin = 17;//30;//
        spi_config.mosi_pin = 12;//27;//
        spi_config.sck_pin  = 13;//25;//
        spi_config.frequency    = NRF_DRV_SPI_FREQ_8M;                     
        spi_config.mode         = NRF_DRV_SPI_MODE_1;    //MODE 0 for flash 1 for DAC                  
        spi_config.bit_order    = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
        
        APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));
    
    #define SPI_INSTANCE2  2 /**< SPI instance index. */
    static const nrf_drv_spi_t spi2 = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE2);  /**< SPI instance. */
    
        nrf_drv_spi_config_t spi_config2 = NRF_DRV_SPI_DEFAULT_CONFIG;
        spi_config2.ss_pin   = 29;//30 for sd 16 for afe
        spi_config2.miso_pin = 30;//7
        spi_config2.mosi_pin = 27;//15
        spi_config2.sck_pin  = 25;//12
        spi_config2.frequency    = NRF_DRV_SPI_FREQ_8M;                     
        spi_config2.mode         = NRF_DRV_SPI_MODE_0;                      
        spi_config2.bit_order    = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
        
        APP_ERROR_CHECK(nrf_drv_spi_init(&spi2, &spi_config2, spi_event_handler, NULL));

    In sdk_config.h

    // <e> SPI1_ENABLED - Enable SPI1 instance
    //==========================================================
    #ifndef SPI1_ENABLED
    #define SPI1_ENABLED 1
    #endif
    // <q> SPI1_USE_EASY_DMA  - Use EasyDMA
     
    
    #ifndef SPI1_USE_EASY_DMA
    #define SPI1_USE_EASY_DMA 1
    #endif
    
    // </e>
    
    // <e> SPI2_ENABLED - Enable SPI2 instance
    //==========================================================
    #ifndef SPI2_ENABLED
    #define SPI2_ENABLED 1
    #endif
    // <q> SPI2_USE_EASY_DMA  - Use EasyDMA
     
    
    #ifndef SPI2_USE_EASY_DMA
    #define SPI2_USE_EASY_DMA 1
    #endif
    
    
    // <q> NRFX_SPI1_ENABLED  - Enable SPI1 instance
     
    
    #ifndef NRFX_SPI1_ENABLED
    #define NRFX_SPI1_ENABLED 1
    #endif
    
    // <q> NRFX_SPI2_ENABLED  - Enable SPI2 instance
     
    
    #ifndef NRFX_SPI2_ENABLED
    #define NRFX_SPI2_ENABLED 1
    #endif

    Still, I am getting build errors. Can you please check. 

Reply
  • I am trying to use instances 1 and 2 as you suggested.
    In the main file: 

    #define SPI_INSTANCE  1 /**< SPI instance index. */
    static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */
    
        nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
        spi_config.ss_pin   = 11;//29;//
        spi_config.miso_pin = 17;//30;//
        spi_config.mosi_pin = 12;//27;//
        spi_config.sck_pin  = 13;//25;//
        spi_config.frequency    = NRF_DRV_SPI_FREQ_8M;                     
        spi_config.mode         = NRF_DRV_SPI_MODE_1;    //MODE 0 for flash 1 for DAC                  
        spi_config.bit_order    = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
        
        APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));
    
    #define SPI_INSTANCE2  2 /**< SPI instance index. */
    static const nrf_drv_spi_t spi2 = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE2);  /**< SPI instance. */
    
        nrf_drv_spi_config_t spi_config2 = NRF_DRV_SPI_DEFAULT_CONFIG;
        spi_config2.ss_pin   = 29;//30 for sd 16 for afe
        spi_config2.miso_pin = 30;//7
        spi_config2.mosi_pin = 27;//15
        spi_config2.sck_pin  = 25;//12
        spi_config2.frequency    = NRF_DRV_SPI_FREQ_8M;                     
        spi_config2.mode         = NRF_DRV_SPI_MODE_0;                      
        spi_config2.bit_order    = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
        
        APP_ERROR_CHECK(nrf_drv_spi_init(&spi2, &spi_config2, spi_event_handler, NULL));

    In sdk_config.h

    // <e> SPI1_ENABLED - Enable SPI1 instance
    //==========================================================
    #ifndef SPI1_ENABLED
    #define SPI1_ENABLED 1
    #endif
    // <q> SPI1_USE_EASY_DMA  - Use EasyDMA
     
    
    #ifndef SPI1_USE_EASY_DMA
    #define SPI1_USE_EASY_DMA 1
    #endif
    
    // </e>
    
    // <e> SPI2_ENABLED - Enable SPI2 instance
    //==========================================================
    #ifndef SPI2_ENABLED
    #define SPI2_ENABLED 1
    #endif
    // <q> SPI2_USE_EASY_DMA  - Use EasyDMA
     
    
    #ifndef SPI2_USE_EASY_DMA
    #define SPI2_USE_EASY_DMA 1
    #endif
    
    
    // <q> NRFX_SPI1_ENABLED  - Enable SPI1 instance
     
    
    #ifndef NRFX_SPI1_ENABLED
    #define NRFX_SPI1_ENABLED 1
    #endif
    
    // <q> NRFX_SPI2_ENABLED  - Enable SPI2 instance
     
    
    #ifndef NRFX_SPI2_ENABLED
    #define NRFX_SPI2_ENABLED 1
    #endif

    Still, I am getting build errors. Can you please check. 

Children
Related