cancel
Showing results for 
Search instead for 
Did you mean: 

I'm monitorating heart rate by the MAX30100(https://img.filipeflop.com/files/download/Datasheet_MAX30100.pdf) using the MCU STM32F4. I'm trying read the IR and RED data from the FIFO, but all returns are **ZERO**.

FFern.1463
Associate

I'm monitorating heart rate by the MAX30100(https://img.filipeflop.com/files/download/Datasheet_MAX30100.pdf) using the MCU STM32F4. I'm trying read the IR and RED data from the FIFO, but all returns are **ZERO**. The method `MAX30100_Get_Num_Samples()` returns **8**. I modeled the code using the pseudo code from datasheet of MAX30100. I tried several solutions for my problem but doesn't work. I dont know if i'm following the right way to get data from the FIFO. My code:

  I2C_HandleTypeDef hi2c3; //i2c used

  uint16_t RED[50] = {0}, IR[50] = {0}; //buffers for RED and IR

  uint8_t buffOximeter[5];

  char buffer[32];

  int main(void)

  {

   HAL_Init();

   SystemClock_Config();

   MX_GPIO_Init();

   MX_I2C3_Init();

   MX_USB_DEVICE_Init();

   MAX30100_Init();

   while (1)

   {

  uint8_t numSamples = MAX30100_Get_Num_Samples();

  MAX30100_Read_HeartBeat(numSamples);

  for(int i = 0; i < numSamples; i++)

  {

  sprintf(buffer, "Amostra %d: %d / %d\n\r", i , IR[i], RED[i]);

  CDC_Transmit_FS((char*)buffer, 50);

  }

   }

  }

  static void MX_I2C3_Init(void)

  {

   hi2c3.Instance = I2C3;

   hi2c3.Init.ClockSpeed = 400000;

   hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;

   hi2c3.Init.OwnAddress1 = 0;

   hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;

   hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;

   hi2c3.Init.OwnAddress2 = 0;

   hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;

   hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;

   if (HAL_I2C_Init(&hi2c3) != HAL_OK)

   {

    Error_Handler();

   }

  }

  void MAX30100_Init(void)

  {

  HAL_I2C_Mem_Write(&hi2c3,0xAE,0x06,1,0x02,1,1000); //set heart rate mode

  HAL_I2C_Mem_Write(&hi2c3,0xAE,0x09,1,0xFF,1,1000); //i50 ledCurrent

  uint8_t sr = 0x01, pw = 0x3;

  HAL_I2C_Mem_Write(&hi2c3,0xAE,0x07,1,(sr<<2)|pw,1,1000); //sr100, pw1600

  HAL_Delay(50);

  }

  void MAX30100_Read_HeartBeat(uint8_t num)

  {

  for(int i=0;i<num;i++)

    {

  HAL_I2C_Master_Transmit(&hi2c3,0x57,0xAE,1,1000); //adress + write mode

  HAL_I2C_Master_Transmit(&hi2c3,0x57,0x02,1,1000); //send fifo_wr_ptr

  HAL_I2C_Master_Transmit(&hi2c3,0x57,0xAF,1,1000); //adress + read mode

  uint8_t data;

  HAL_I2C_Master_Receive(&hi2c3,0x57,&data,1,1000); //read fifo_wr_ptr

  HAL_Delay(100);  //STOP

  HAL_I2C_Master_Transmit(&hi2c3,0x57,0xAE,1,1000); //adress + write mode

  HAL_I2C_Master_Transmit(&hi2c3,0x57,0x05,1,1000); //send adress fifo data

  HAL_I2C_Master_Transmit(&hi2c3,0x57,0xAF,1,1000); //adress + read mode

  HAL_I2C_Mem_Read(&hi2c3,0x57,0x05,1,&buffOximeter,4,1000); //read fifo data

  IR[i] = (buffOximeter[0] << 8) | buffOximeter[1];

  RED[i] = (buffOximeter[2] << 8) | buffOximeter[3];

  HAL_Delay(100);                  //STOP

  HAL_I2C_Master_Transmit(&hi2c3,0x57,0xAE,1,1000); //adress + write mode

  HAL_I2C_Master_Transmit(&hi2c3,0x57,0x04,1,1000); //send adress fifo_rd_ptr

  HAL_Delay(100);

  }

  }

  int MAX30100_Get_Num_Samples(void)

  {

  uint8_t wrPtr, rdPtr;

  HAL_I2C_Mem_Read(&hi2c3,0x57,0x02,1,&wrPtr,1,1000);

  HAL_Delay(50);

  HAL_I2C_Mem_Read(&hi2c3,0x57,0x04,1,&rdPtr,1,1000);

  HAL_Delay(50);

    return (abs( 16 + wrPtr - rdPtr ) % 16);

  }

4 REPLIES 4
Eleon BORLINI
ST Employee

Hi @FFern.1463​ , I suggest you to post the same question on the STM32 community page and/or on Maxim Q&A page, being the MAX30100 a Maxim sensor. Regards

What kind of forum software are you running? Just move posts to the appropriate sub-forum..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

It is just a matter of editing tags (topics), I did it.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Thanks

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..