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

Nordic Thingy 52 - external I2C sensor device driver implementation

Hello everyone,

i'm trying to hook up an external i2C sensor to P5 connector (TWI_SCL_EXT, TWI_SDA_EXT) and created a device driver template ( from drv_gas_sensor.c example) .

to start with  i have created this function in m_environment.c:

/**@brief Function for initializing the MY sensor
 */
static uint32_t my_sensor_init(const nrf_drv_twi_t * p_twi_instance)
{
    uint32_t       err_code;
    drv_my_init_t init_params;

    static const nrf_drv_twi_config_t twi_config =
    {
        .scl                = TWI_SCL_EXT,
        .sda                = TWI_SDA_EXT,
        .frequency          = NRF_TWI_FREQ_400K,
        .interrupt_priority = APP_IRQ_PRIORITY_LOW
    };

    init_params.p_twi_instance = p_twi_instance;
    init_params.p_twi_cfg      = &twi_config;
    init_params.twi_addr       = MY_ADDR;
    init_params.data_handler   = drv_my_data_handler;

    err_code = drv_my_init(&init_params);
    RETURN_IF_ERROR(err_code);

    return NRF_SUCCESS;

}

//and calling this function in  m_environment_init() function as below

     err_code = my_sensor_init(p_params->p_twi_instance);
    APP_ERROR_CHECK(err_code);

let me know if this is right.

Related