从模块读取了数据,还需要一系列算法才能利用这些数据
This commit is contained in:
+90
-1
@@ -6,15 +6,104 @@
|
||||
*/
|
||||
|
||||
#include "APP_blood.h"
|
||||
|
||||
#include "iic.h"
|
||||
window *blood_win;
|
||||
uint16_t fifo_red;
|
||||
uint16_t fifo_ir;
|
||||
char blood_str[64];
|
||||
uint8_t Max30102_reset(void)
|
||||
{
|
||||
char a=0x40;
|
||||
IIC_SAND_DATE(MAX30102_Device_address,REG_MODE_CONFIG, &a,1);
|
||||
|
||||
}
|
||||
void MAX30102_Config(void)
|
||||
{
|
||||
char a;
|
||||
a=0xc0;
|
||||
IIC_SAND_DATE(MAX30102_Device_address,REG_INTR_ENABLE_1,&a,1);//// INTR setting
|
||||
a=0;
|
||||
IIC_SAND_DATE(MAX30102_Device_address,REG_INTR_ENABLE_2,&a,1);//
|
||||
IIC_SAND_DATE(MAX30102_Device_address,REG_FIFO_WR_PTR,&a,1);//FIFO_WR_PTR[4:0]
|
||||
IIC_SAND_DATE(MAX30102_Device_address,REG_OVF_COUNTER,&a,1);//OVF_COUNTER[4:0]
|
||||
IIC_SAND_DATE(MAX30102_Device_address,REG_FIFO_RD_PTR,&a,1);//FIFO_RD_PTR[4:0]
|
||||
|
||||
a=0x0f;
|
||||
IIC_SAND_DATE(MAX30102_Device_address,REG_FIFO_CONFIG,&a,1);//sample avg = 1, fifo rollover=false, fifo almost full = 17
|
||||
a=0x03;
|
||||
IIC_SAND_DATE(MAX30102_Device_address,REG_MODE_CONFIG,&a,1);//0x02 for Red only, 0x03 for SpO2 mode 0x07 multimode LED
|
||||
a=0x27;
|
||||
IIC_SAND_DATE(MAX30102_Device_address,REG_SPO2_CONFIG,&a,1); // SPO2_ADC range = 4096nA, SPO2 sample rate (50 Hz), LED pulseWidth (400uS)
|
||||
a=0x32;
|
||||
IIC_SAND_DATE(MAX30102_Device_address,REG_LED1_PA,&a,1);//Choose value for ~ 10mA for LED1
|
||||
IIC_SAND_DATE(MAX30102_Device_address,REG_LED2_PA,&a,1);// Choose value for ~ 10mA for LED2
|
||||
a=0x7f;
|
||||
IIC_SAND_DATE(MAX30102_Device_address,REG_PILOT_PA,&a,1);// Choose value for ~ 25mA for Pilot LED
|
||||
}
|
||||
void max30102_read_fifo(void)
|
||||
{
|
||||
uint16_t un_temp;
|
||||
fifo_red=0;
|
||||
fifo_ir=0;
|
||||
uint8_t ach_i2c_data[6];
|
||||
|
||||
//read and clear status register
|
||||
IIC_READ_DATE(MAX30102_Device_address,REG_INTR_STATUS_1,&ach_i2c_data,1);
|
||||
IIC_READ_DATE(MAX30102_Device_address,REG_INTR_STATUS_2,&ach_i2c_data,1);
|
||||
|
||||
ach_i2c_data[0]=REG_FIFO_DATA;
|
||||
|
||||
IIC_READ_DATE(MAX30102_Device_address,REG_FIFO_DATA,&ach_i2c_data,6);
|
||||
|
||||
un_temp=ach_i2c_data[0];
|
||||
un_temp<<=14;
|
||||
fifo_red+=un_temp;
|
||||
un_temp=ach_i2c_data[1];
|
||||
un_temp<<=6;
|
||||
fifo_red+=un_temp;
|
||||
un_temp=ach_i2c_data[2];
|
||||
un_temp>>=2;
|
||||
fifo_red+=un_temp;
|
||||
|
||||
un_temp=ach_i2c_data[3];
|
||||
un_temp<<=14;
|
||||
fifo_ir+=un_temp;
|
||||
un_temp=ach_i2c_data[4];
|
||||
un_temp<<=6;
|
||||
fifo_ir+=un_temp;
|
||||
un_temp=ach_i2c_data[5];
|
||||
un_temp>>=2;
|
||||
fifo_ir+=un_temp;
|
||||
|
||||
if(fifo_ir<=10000)
|
||||
{
|
||||
fifo_ir=0;
|
||||
}
|
||||
if(fifo_red<=10000)
|
||||
{
|
||||
fifo_red=0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void APP_blood_init(window *a_window)
|
||||
{
|
||||
blood_win=a_window;
|
||||
Max30102_reset();
|
||||
MAX30102_Config();
|
||||
|
||||
//HAL_GPIO_WritePin(MAX_RD_GPIO_Port, MAX_RD_Pin, 0);
|
||||
}
|
||||
|
||||
void APP_blood_loop()
|
||||
{
|
||||
max30102_read_fifo();
|
||||
sprintf(blood_str,"fifo_red:%d",fifo_red);
|
||||
LCD_ShowString(blood_win->x, blood_win->y+16, &blood_str, 16, WHITE, RED);
|
||||
sprintf(blood_str,"fifo_ir:%d",fifo_ir);
|
||||
LCD_ShowString(blood_win->x, blood_win->y+32, &blood_str, 16, WHITE, RED);
|
||||
sprintf(blood_str,"INT:%d",HAL_GPIO_ReadPin(MAX_INT_GPIO_Port, MAX_INT_Pin));
|
||||
LCD_ShowString(blood_win->x, blood_win->y+48, &blood_str, 16, WHITE, RED);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,33 @@
|
||||
#include "windows.h"
|
||||
#include "LCD.h"
|
||||
|
||||
#define MAX30102_Device_address 0xAE
|
||||
//register addresses
|
||||
#define REG_INTR_STATUS_1 0x00
|
||||
#define REG_INTR_STATUS_2 0x01
|
||||
#define REG_INTR_ENABLE_1 0x02
|
||||
#define REG_INTR_ENABLE_2 0x03
|
||||
#define REG_FIFO_WR_PTR 0x04
|
||||
#define REG_OVF_COUNTER 0x05
|
||||
#define REG_FIFO_RD_PTR 0x06
|
||||
#define REG_FIFO_DATA 0x07
|
||||
#define REG_FIFO_CONFIG 0x08
|
||||
#define REG_MODE_CONFIG 0x09
|
||||
#define REG_SPO2_CONFIG 0x0A
|
||||
#define REG_LED1_PA 0x0C
|
||||
#define REG_LED2_PA 0x0D
|
||||
#define REG_PILOT_PA 0x10
|
||||
#define REG_MULTI_LED_CTRL1 0x11
|
||||
#define REG_MULTI_LED_CTRL2 0x12
|
||||
#define REG_TEMP_INTR 0x1F
|
||||
#define REG_TEMP_FRAC 0x20
|
||||
#define REG_TEMP_CONFIG 0x21
|
||||
#define REG_PROX_INT_THRESH 0x30
|
||||
#define REG_REV_ID 0xFE
|
||||
#define REG_PART_ID 0xFF
|
||||
|
||||
#define SAMPLES_PER_SECOND 100 //¼ì²âƵÂÊ
|
||||
|
||||
void APP_blood_init(window *a_window);
|
||||
void APP_blood_loop();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user