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

TWI communication issue with nRF52840 Dongle

Dear Nordic Team,

We are working on connecting an I2C device to an nRF52840 Dongle. The code we are using is one we've been developing for a few weeks with an nRF52840 DK with which it works fine. As we're making the transition to the dongle we've incrementally enabled portions of the code (led, button, BLE all work), but the I2C gets stuck: NRF_DRV_TWI_EVT_DONE event never happens after first call of nrf_drv_twi_tx. Previously with the DK if this happened it was always a soldering/connection issue, but it doesn't seem to be the problem here.

Rather, I suspect the GPIO pin configuration is the problem. We've attached snapshots of the code segments where we initialize the TWI and define the GPIO pins. is there any other step specific to the dongle we need to take to resolve the issue?

Thank you in advance,

George

define pins

I2C init and write

HW connections

  • void i2c_write( uint8_t address, uint8_t * data, int count ) {
        m_xfer_done = false;
        m_err_code = nrf_drv_twi_tx( &m_twi, address, data, count, false );
        if ( m_err_code != NRF_SUCCESS ) {
          NRF_LOG_DEBUG( "I2C WRITE ERROR: %d\r\n", m_err_code );
        }
        while (m_xfer_done == false){
        blinkit();
        };
        APP_ERROR_CHECK( m_err_code );
    }
    
    /* Blocking reading call for I2C */
    void i2c_read( uint8_t address, uint8_t * data, int count ) {
        m_xfer_done = false;
        m_err_code = nrf_drv_twi_rx( &m_twi, address, data, count );
        if ( m_err_code != NRF_SUCCESS ) {
        	NRF_LOG_DEBUG( "I2C READ ERROR: %d\r\n", m_err_code );
            printf( "I2C READ ERROR: %d\r\n", m_err_code );
        }
        while (m_xfer_done == false);
        APP_ERROR_CHECK( m_err_code );
    }
    
    /**
     * @brief TWI events handler.
     */
    void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
    {
        switch (p_event->type)
        {
            case NRF_DRV_TWI_EVT_DONE:
                m_xfer_done = true;
                break;
            default:
                break;
        }
    }
    
    void twi_init(void){
    
        ret_code_t err_code;
    
        const nrf_drv_twi_config_t twi_LSM6DS33_config = {
           .scl                = SCL_PIN,
           .sda                = SDA_PIN,
           .frequency          = NRF_DRV_TWI_FREQ_400K,
           .interrupt_priority = APP_IRQ_PRIORITY_LOW,
           .clear_bus_init     = false
        };
    
        err_code = nrf_drv_twi_init(&m_twi, &twi_LSM6DS33_config, twi_handler, NULL);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_twi_enable(&m_twi);
    }

    TWI init and write

    #ifndef PCA10059_H
    #define PCA10059_H
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    #include "nrf_gpio.h"
    
    // LED definitions for PCA10059
    // Each LED color is considered a separate LED
    #define LEDS_NUMBER    4
    
    #define LED1_G         NRF_GPIO_PIN_MAP(0,6)
    #define LED2_R         NRF_GPIO_PIN_MAP(0,8)
    #define LED2_G         NRF_GPIO_PIN_MAP(1,9)
    #define LED2_B         NRF_GPIO_PIN_MAP(0,12)
    
    #define LED_1          LED1_G
    #define LED_2          LED2_R
    #define LED_3          LED2_G
    #define LED_4          LED2_B
    
    #define LEDS_ACTIVE_STATE 0
    
    #define LEDS_LIST { LED_1, LED_2, LED_3, LED_4 }
    
    #define LEDS_INV_MASK  LEDS_MASK
    
    #define BSP_LED_0      LED_1
    #define BSP_LED_1      LED_2
    #define BSP_LED_2      LED_3
    #define BSP_LED_3      LED_4
    
    // There is only one button for the application
    // as the second button is used for a RESET.
    #define BUTTONS_NUMBER 1
    
    #define BUTTON_1       NRF_GPIO_PIN_MAP(1,6)
    #define BUTTON_PULL    NRF_GPIO_PIN_PULLUP
    
    #define BUTTONS_ACTIVE_STATE 0
    
    #define BUTTONS_LIST { BUTTON_1 }
    
    #define BSP_BUTTON_0   BUTTON_1
    
    #define BSP_SELF_PINRESET_PIN NRF_GPIO_PIN_MAP(0,19)
    
    #define SDA_PIN       NRF_GPIO_PIN_MAP(0,9)
    #define SCL_PIN       NRF_GPIO_PIN_MAP(0,10)
    
    #define HWFC           true
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif // PCA10059_H
    

    Pin define

  • Hi,

     

    It seems that you're using the NFC pins as TWI SCL/SDA pins (P0.09 and P0.10). You need the preprocessor define "CONFIG_NFCT_PINS_AS_GPIOS" set in order to use those as normal GPIOs, or use any other available GPIOs for this purpose. On development kits (nrf52-DK, nrf52840-DK, etc), you also need to move some zero-ohm resistors to route the signals to the pin header.

     

    Kind regards,

    Håkon

Related