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

SPI and TWI Error

I'm writing an nRF52 DK btle application using SDK 12. The DK comunicates with 2 external peripheral via SPI and I2C interfaces. Complilation fails with the error:

._build\spi_twi_example.axf: Error: L6200E: Symbol SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler multiply defined (by nrf_drv_twi.o and nrf_drv_spi.o).

Why? Thanks in advance.

  • Looks like you are trying to use both SPI0 and TWI0 in the same application, which will not work. You will have to change either SPI0 to SPI1, or TWI0 to TWI1. You do this with

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

    or

    #define TWI_INSTANCE     1 /**< TWI instance index. */
    static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE); /**< TWI instance. */
    ...
    

    This table in the Product Specification tells you which peripherals that cannot be used together.

  • Hello, Ole Bauck. In the "Product Specification table",

    SPIM0, SPIS0, TWIM0, and others share the same base address, which is 0x40003000.

    Do you mean that the reason is that SPI0 and TWI0 instances share the same resources?

    -Best Regards

  • Yes, that's correct. SPIM0, SPIS0, TWIM0, TWIS0, SPI0 and TWI0 all use the same peripheral hardware registers, so trying to configure more than one of these simultaneously will not work. If you first configure TWI0, and then SPI0, the SPI0 configuration would overwrite the TWI0 configuration.

  • Hello,

    I have the same problem, but when 2 declared different instance number of TWI and SPI, it still didn't work, bellow is my code :

    #include "spi.hpp"
    #include "nrf_drv_spi.h"
    
    #define CS_PIN 6
    #define DQ0 22
    #define DQ1 19
    #define DQ2 20
    #define DQ3 24
    #define CLK 23
    
    #define     SPI_INSTANCE  1 
    #define     SPI1_USE_EASY_DMA 1
    
    static const nrf_drv_spi_t spi1 = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); 
    static bool spi_xfer_done;  /**< Flag used to indicate that SPI instance completed the transfer. */
    static nrf_drv_spi_xfer_desc_t xfer_desc;
    
    static uint8_t rxBuffer[100], txBuffer[100];
    
    void spi_event_handler(nrf_drv_spi_evt_t const *p_event)
    {
        switch (p_event->type)
        {
            case NRF_DRV_SPI_EVENT_DONE:
            nrf_drv_spi_xfer(&spi1, &xfer_desc, 0);
            spi_xfer_done = true;
        }
    }
    
    void initSPI()
    {
            xfer_desc.p_tx_buffer = txBuffer;
            xfer_desc.p_rx_buffer = rxBuffer;
            xfer_desc.tx_length   = 100;
            xfer_desc.rx_length   = 100;
    
            nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    
            spi_config.ss_pin   = CS_PIN;
            spi_config.miso_pin = DQ1;
            spi_config.mosi_pin = DQ0 ;
            spi_config.sck_pin  = CLK;
    
            nrf_drv_spi_init(&spi1, &spi_config, spi_event_handler);
            nrf_drv_spi_transfer(&spi1,txBuffer , 100, NULL, 0);
    }
    
  • Hello You say you use both TWI and SPI, but the code you posted is only about the SPI. Could you please post the code relating to the TWI as well?

Related