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

Why cannot I receive second byte of MAX30205 with nrf_drv_twi_xfer()?

Hello,

I am using nrf52832 with PCA10040 and SDK15.1 along with a temperature sensor MAX30205. So far I can write, but I am realizing that I cannot read the second byte of the temperature given by the sensor using the function nrf_drv_twi_xfer() of the driver...

My function looks like this

int8_t twi1_ext_read_transfer(uint8_t i2cAddressMAX30205, uint8_t reg_addr,char *rxData, uint16_t bytesNumberRx,bool repeatedStart) {

  ret_code_t err_code;


    nrf_drv_twi_xfer_desc_t twi_MAX30205_ReadTransferData;

    twi_MAX30205_ReadTransferData.address          = i2cAddressMAX30205;
    twi_MAX30205_ReadTransferData.p_primary_buf    = &reg_addr;
    twi_MAX30205_ReadTransferData.primary_length   = sizeof(reg_addr);
    twi_MAX30205_ReadTransferData.p_secondary_buf  = rxData;
    twi_MAX30205_ReadTransferData.secondary_length = bytesNumberRx;
    if(repeatedStart){
        twi_MAX30205_ReadTransferData.type             = NRF_DRV_TWI_XFER_TXRX;
    } else {
        twi_MAX30205_ReadTransferData.type             = NRF_DRV_TWI_XFER_RX;
    }

    uint32_t flags = NRF_DRV_TWI_FLAG_NO_XFER_EVT_HANDLER;

    err_code = nrf_drv_twi_xfer(&twi_MAX30205, &twi_MAX30205_ReadTransferData, flags);

    APP_ERROR_CHECK(err_code);

    #if defined(DEBUG_INTERFACE_MAX30205) && defined(EXG_MODULE_TMIC_DK)
        NRF_LOG_RAW_INFO("TW1:From device address 0x%04x reading register 0x%04x value 0x%04x \r\n",i2cAddressMAX30205,reg_addr,*rxData);
    #endif

    return ((int8_t)err_code);    
}

If I use that, when calling driver function I see how last byte `data[1]` seems not to have right value

int max30205_read_reg16(int16_t *value, char reg)//, I2C &i2c_bus) 
{
    int32_t ret;
    char data[2] = {0, 0};
    max30205_raw_data tmp;

    tmp.msb =0;
    tmp.lsb=0;
     
    if (reg == MAX30205_REG_TEMPERATURE || 
        reg == MAX30205_REG_THYST_LOW_TRIP || reg == MAX30205_REG_TOS_HIGH_TRIP) {

            ret = twi1_ext_read_transfer(max30205_address, reg, data, 2, true);

            if (ret == 0) {
                tmp.msb = data[0];
                tmp.lsb = data[1];
                *value = tmp.swrd;
                return MAX30205_NO_ERROR;
            } else {
                printf(
                    "%s: failed to read data: ret: %d\r\n", __func__, ret);
            }

    } else {
        printf("%s: register address is not correct: register: %d\r\n",
                __func__, reg);
    }                
    return MAX30205_ERROR;
}

Can someone give me a hint?

Thanks in advance

Parents Reply Children
Related