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

Why is the TWI_Mngr busy when I use SPI_Mngr too?

Hello,

I have an application that uses the SPI- and the TWI-Manager:

#define I2C_SDA                                         26                                      /**< Pin used for the SDA signal by the I2C module. */
#define I2C_SCL                                         27                                      /**< Pin used for the SCL signal by the I2C module. */

#define SPI_SS                                          22                                      /**< Pin used for the nSS signal by the SPI module. */
#define SPI_MOSI                                        23                                      /**< Pin used for the MOSI signal by the SPI module. */
#define SPI_MISO                                        24                                      /**< Pin used for the MISO signal by the SPI module. */
#define SPI_SCLK                                        25                                      /**< Pin used for the SCLK signal by the SPI module. */

NRF_TWI_MNGR_DEF(TWI_Mngr, 15, 0);
NRF_SPI_MNGR_DEF(SPI_Mngr, 15, 0);

void Init_SPI(void)
{
    const nrf_drv_spi_config_t SPI_Config = {
        .ss_pin		= SPI_SS,
	.miso_pin	= SPI_MISO,
	.mosi_pin	= SPI_MOSI,
	.sck_pin        = SPI_SCLK,
        .irq_priority   = APP_IRQ_PRIORITY_LOWEST,
        .orc            = 0xFF,
        .frequency      = NRF_DRV_SPI_FREQ_8M,
        .mode           = NRF_DRV_SPI_MODE_0,
        .bit_order      = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST
    };

    NRF_LOG_DEBUG("Initialize SPI manager...");

    APP_ERROR_CHECK(nrf_spi_mngr_init(&SPI_Mngr, &SPI_Config));
}

void Init_TWI(void)
{
    uint8_t Dummy;

    const nrf_drv_twi_config_t TWI_Config = {
       .scl		    = I2C_SCL,
       .sda		    = I2C_SDA,
       .frequency	    = NRF_DRV_TWI_FREQ_100K,
       .interrupt_priority  = APP_IRQ_PRIORITY_LOWEST,
       .clear_bus_init	    = false
    };

    // Initialize the TWI manager
    NRF_LOG_DEBUG("Initialize TWI manager...");
    APP_ERROR_CHECK(nrf_twi_mngr_init(&TWI_Mngr, &TWI_Config));
}

int main(void)
{
    Init_SPI();
    Init_TWI();
}

But the application throws the error code 17 when the program tries to initialize the TWI-Manager. When I change 

NRF_TWI_MNGR_DEF(TWI_Mngr, 15, 0);

to

NRF_TWI_MNGR_DEF(TWI_Mngr, 15, 1);

the problem is gone. 

So why does the SPI-Manager affect the TWI-Manager? I read the docs and the last parameter is the TWI / SPI module in the microcontroller, so it should be no problem to use the interface with the number 0 for both libraries.

Edit:

The same behavior occurs when I use the raw SPI and TWI driver instead of the manager libraries.

Related