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

nRF52840 - Configure TWI pins on PORT1

Hello,

I am currently working on a custom nRF52840 board. I have to make the nRF52 communicate with a chip using TWI, so I started from SDK 15.2.0 TWI Scanner example.

The pinout is the following:

- SCL: P1.09

- SDA: P0.12

To make the TWI driver work with PORT1 gpios I used the macro NRF_GPIO_PIN_MAP:

/**
 * @brief TWI initialization.
 */
void twi_init (void)
{
    ret_code_t err_code;

    const nrf_drv_twi_config_t twi_config = {
       .scl                = NRF_GPIO_PIN_MAP(1, 9),
       .sda                = NRF_GPIO_PIN_MAP(0, 12),
       .frequency          = NRF_DRV_TWI_FREQ_400K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
       .clear_bus_init     = false
    };

    err_code = nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL);
    APP_ERROR_CHECK(err_code);

    nrf_drv_twi_enable(&m_twi);
}

But when I run the application, the execution is stuck in this loop of nrfx_twim.c starting from line 441:

while (!nrf_twim_event_check(p_twim, evt_to_wait))
{
    if (nrf_twim_event_check(p_twim, NRF_TWIM_EVENT_ERROR))
    {
        NRFX_LOG_DEBUG("TWIM: Event: %s.", EVT_TO_STR_TWIM(NRF_TWIM_EVENT_ERROR));
        nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_ERROR);
        nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_RESUME);
        nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_STOP);
        evt_to_wait = NRF_TWIM_EVENT_STOPPED;
    }
}

Can you please tell me what I am doing wrong and what to do to make TWI work with PORT1 gpios ?

Thank you very much !

Bilal

Related