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

TWI driver for register-less chips with Thingy: 52

Helllo,

i'm using a custom shield with the Thingy:52.

I need to control some TWI chips, but these chips (ADG728) have only one register.

I have done a specific driver for these chips, based on the drv_mpu9250, and using nrf_drv_twi_tx function.

It works well, but, as the chip contain just one register, i change the 3rd parameter of the function nrf_drv_twi_tx to NULL for reding the register contents.

TWI transfer is good, but the driver return the error code INTERNAL_ERROR. 

I want to know how i can't dig deeper into the driver layers to modify the ERROR_CODE to fit my specific "no-register" case.

Thanks,

Arnaud

  • Hi,

     Which function returns the error code, nrf_drv_twi_tx ? How does SCL and SDA look like when the error is returned? The INTERNAL_ERROR code is a generic error that can be returned in more than one scenario. Modifying the error handler to ignore that error is therefore not optimal. Could you post some code?

     regards

    Jared

  • This is the function inside drv_ADG728.c (based on the drv_mpu9250), where the error code is returned (from nrf_drv_twi_tx):

    int drv_ADG728_read(unsigned char slave_addr, unsigned char * data)
    {
        uint32_t err_code;
    
        err_code = twi_open();
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_twi_tx( m_ADG728.init.p_twi_instance,
                                   slave_addr,
                                   NULL,//&reg_addr,
                                   0,
                                   true);
        if (err_code != NRF_SUCCESS)
        {
            NRF_LOG_ERROR("drv_ADG728_read Failed! = %d\r\n", err_code);
        }
    
        err_code = nrf_drv_twi_rx( m_ADG728.init.p_twi_instance,
                                   slave_addr,
                                   data,
                                   1 );
        if (err_code != NRF_SUCCESS)
        {
            NRF_LOG_ERROR("drv_ADG728_read Failed!\r\n");
        }
    
        err_code = twi_close();
        APP_ERROR_CHECK(err_code);
    
        return 0;
    }

    I use it in a intialisation function, in shield_manager_init():

    static void shield_init(void)
    {
        uint32_t            err_code;
        drv_ADG728_init_t  ADG728_init_params;
        drv_AD5245_init_t  AD5245_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,  //APP_IRQ_PRIORITY_LOW 
        };
      
        ADG728_init_params.p_twi_instance = &m_twi_sensors;
        ADG728_init_params.p_twi_cfg = &twi_config;
    
        err_code = drv_ADG728_init(&ADG728_init_params);
        APP_ERROR_CHECK(err_code);
    
        AD5245_init_params.p_twi_instance = &m_twi_sensors;
        AD5245_init_params.p_twi_cfg = &twi_config;
    
        err_code = drv_AD5245_init(&AD5245_init_params);
        APP_ERROR_CHECK(err_code);
    
        err_code = shield_manager_init();
        APP_ERROR_CHECK(err_code);
    
    }

    SCL and SCA look great, and i can read the data previously written onto the ADG728 register...

    It's like there is an error, but i don't see it, everithing works fine...

  • Hi,

     I'm not sure if it's necessary to do a transmit sequence before you do a read based on the read sequence from the datasheet:

    It seems that you assume that it's necessary to do a transmit sequence first? Maybe there is something I've missed? Slight smile

  • I think you're right and missed nothing. I'll try it out and confirm later.

    Thanks

  • I confirm you where perfectly right!

    Thanks

Related