Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI read is not happening

Hi,

I am trying to read data from a temperature sensor, but i'm stuck at the twi read operation. i have already interfaced the sensor with esp32 and is working fine. please see the attached screen-shot. 

but from nrf, only the first write is going not the read command. even if i try to write again, it is also not working ie. it is not giving the start condition.

I am using nrf52832, sdk14.0

Parents
  • Hi, 

    • Can you post the code showing how you perform you reads and writes?
    • What TWI slave are you using?
    • I don't see what is wrong in your logic traces. The green dots are start conditions, and the brown dots are stop conditions. In your first image it looks like you try to read from register 0 by writing a byte with value 0, which the slave ACKs, and then start a TWI read operation where the slave responds with value 0x1F.
  • Thanks for the reply Martin,

    I am using max30205

    your understanding of the logic trace is correct, but only the first write is happening properly. after that if i try to read or write, its not coming

    void twi_init (void)
    {
        ret_code_t err_code;

        const nrf_drv_twi_config_t twi_lm75b_config = {
           .scl                = MLX_CLOCK_PIN,
           .sda                = MLX_DATA_PIN,
           .frequency          = NRF_TWI_FREQ_400K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
           .clear_bus_init     = false
        };

        err_code = nrf_drv_twi_init(&m_twi, &twi_lm75b_config, twi_handler, NULL);
        APP_ERROR_CHECK(err_code);

        nrf_drv_twi_enable(&m_twi);
    }

    TWI Read

    uint8_t reg[1] = {0 };
     
     nrf_drv_twi_tx(&m_twi, MAX30205_SENSOR_ADDR, reg, sizeof(reg), false);
     while (m_xfer_done == false);
           
     err_code =  nrf_drv_twi_rx(&m_twi, MAX30205_SENSOR_ADDR, m_sample, 2);
     APP_ERROR_CHECK(err_code);

Reply
  • Thanks for the reply Martin,

    I am using max30205

    your understanding of the logic trace is correct, but only the first write is happening properly. after that if i try to read or write, its not coming

    void twi_init (void)
    {
        ret_code_t err_code;

        const nrf_drv_twi_config_t twi_lm75b_config = {
           .scl                = MLX_CLOCK_PIN,
           .sda                = MLX_DATA_PIN,
           .frequency          = NRF_TWI_FREQ_400K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
           .clear_bus_init     = false
        };

        err_code = nrf_drv_twi_init(&m_twi, &twi_lm75b_config, twi_handler, NULL);
        APP_ERROR_CHECK(err_code);

        nrf_drv_twi_enable(&m_twi);
    }

    TWI Read

    uint8_t reg[1] = {0 };
     
     nrf_drv_twi_tx(&m_twi, MAX30205_SENSOR_ADDR, reg, sizeof(reg), false);
     while (m_xfer_done == false);
           
     err_code =  nrf_drv_twi_rx(&m_twi, MAX30205_SENSOR_ADDR, m_sample, 2);
     APP_ERROR_CHECK(err_code);

Children
No Data
Related