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

Using twi vs app_twi

I am trying to set up a humidity sensor over I2C and I'm trying to use the twi interface. There are examples where the app_twi interface is used. I am however unable to get the sensor to respond when using the app_twi interface but can talk to it using the basic twi commands such as nrf_drv_twi_tx. I think the problem might be that the read command implemented as : 

#define MMA7660_READ(p_reg_addr, p_buffer, byte_cnt) \
    APP_TWI_WRITE(MMA7660_ADDR, p_reg_addr, 1,        APP_TWI_NO_STOP), \
    APP_TWI_READ (MMA7660_ADDR, p_buffer,   byte_cnt, 0)

doesn't have a wait between write and read(to account for conversion time and my sensor send a NACK). This is my guess as using the following code makes my sensor work:

        nrf_drv_twi_tx(&m_twi, device_address, dummy_data, sizeof(dummy_data), false);
        nrf_delay_ms(20);

        dummy_data[0] = 0x00;
        nrf_drv_twi_tx(&m_twi, device_address, dummy_data, 1, false);
        nrf_delay_ms(20);

        nrf_drv_twi_rx(&m_twi, device_address, m_sample, sizeof(m_sample));
        nrf_delay_ms(20);

Can you tell me if adding a delay is possible in the macro(if that indeed might be the problem)? How else can I debug this issue in app_twi?

Parents Reply Children
Related