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

Problem reading MAX30101 sensor data from FIFO with NRF52840

Hello everyone,

i have a problem reading data from MAX30101  sensor FIFO. I  set up the sensor and enable all 3 LEDS (Red, IR, Green), but when I read the data from the FIFO I only get data from the first 3 bytes so only for Red LED, from the other leds I get 0s. 

I read the FIFO with a read transaction and store the data to a 9*bytes array. Below is the code I use.

uint8_t slot_temp[9]; //global array

uint8_t max30101_read(uint8_t reg_addr, uint8_t *reg_data)
{   
    //uint8_t *reg_data;
    nrfx_twim_xfer_desc_t desc_read = NRFX_TWIM_XFER_DESC_TXRX(max30101_READ_ADDRS,&reg_addr,sizeof(reg_addr),reg_data,sizeof(reg_data));
    nrfx_err_t twim_xfer_ret = nrfx_twim_xfer(&max30101_twim, &desc_read, 0);
    printk("XFER READ return: %2X \n", twim_xfer_ret);
    if(twim_xfer_ret!=NRFX_SUCCESS) {
      return 0;
    }
    while (m_xfer_done == false);
    return 1;
}

/// inside main :
uint8_t fifo_addr = 0x07;
uint8_t ret = max30101_read(fifo_addr,slot_temp);

I probably do something wrong. 

Has anyone encounter the same problem and get all the 3 LEDs data from MAX30101 .

I will appreciate your help. THANK YOU.

  • This is a bug, since sizeof(blah) returns the size of blah, not what blah points to so in this case it evaluates to 4 (the size of uint32_t pointer address):

    uint8_t max30101_read(uint8_t reg_addr, uint8_t *reg_data)
    {   
        //uint8_t *reg_data;
        nrfx_twim_xfer_desc_t desc_read = NRFX_TWIM_XFER_DESC_TXRX(max30101_READ_ADDRS,&reg_addr,sizeof(reg_addr),reg_data,sizeof(reg_data));

    Try this, as there is no other way to know how many bytes are in parameter reg_data:

    uint8_t max30101_read(uint8_t reg_addr, uint8_t *reg_data, uint16_t reg_length)
    {   
        nrfx_twim_xfer_desc_t desc_read = NRFX_TWIM_XFER_DESC_TXRX(max30101_READ_ADDRS,&reg_addr,sizeof(reg_addr),reg_data,reg_length);

    Parameter reg_length is sizeof(reg_data) in the calling function

      max30101_read(addr, slot_temp, sizeof(slot_temp);

Related