简体   繁体   English

如何使用 STM32F4 从 MAX30100 读取 FIFO 数据

[英]How to read FIFO Data from MAX30100 using STM32F4

i'm monitorating heart rate by the MAX30100( https://img.filipeflop.com/files/download/Datasheet_MAX30100.pdf ) using the MCU STM32F4.我正在使用 MCU STM32F4 通过 MAX30100( https://img.filipeflop.com/files/download/Datasheet_MAX30100.pdf )监测心率。 I'm trying read the IR and RED data from the FIFO, but all returns are ZERO .我正在尝试从 FIFO 中读取 IR 和 RED 数据,但所有返回都是ZERO The method MAX30100_Get_Num_Samples() returns 8 . MAX30100_Get_Num_Samples()方法返回8 I modeled the code using the pseudo code from datasheet of MAX30100.我使用 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.我不知道我是否遵循了从 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);
}

connect the interrupt output pin (pin 13 active low) to an interrupt control pin on the cpu.将中断 output 引脚(引脚 13 低电平有效)连接到 CPU 上的中断控制引脚。

setup your cpu to be interrupted when the device indicates some event ready当设备指示某些事件准备好时,将您的 cpu 设置为中断

Then, still in your interrupt handler function, read register 0 and determine which data is ready,.然后,仍然在您的中断处理程序 function 中,读取寄存器 0 并确定哪些数据已准备好。

the referenced datasheet, approx page 14 lists the order of communication events needed.参考的数据表,大约第 14 页列出了所需的通信事件的顺序。 Note that the posted code is NOT following the specified order of communication events请注意,发布的代码未遵循指定的通信事件顺序

page 16, register 7, indicates how to initialize the SPO2 for the desired mode of operation第 16 页,寄存器 7,指示如何将 SPO2 初始化为所需的操作模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM