#include "MAX30102.h" #include "debug_drv.h" TS_max30102_ ts_max30102; /// ts_max30102.d[6]; uint8 Max30102_reset(void) { #if 0 if(L1_max30102_WB(REG_MODE_CONFIG, 0x40)) return 1; else return 0; #else L1_max30102_WB(REG_MODE_CONFIG, 0x40); return 1; #endif } void MAX30102_Config(void) { L1_max30102_WB(REG_MODE_CONFIG, 0x40);///reset = 1; Lc_delay_ms(30); L1_max30102_WB(REG_INTR_ENABLE_1,0xc0);//// INTR setting 1100 A_FULL_EN PPG_RDY_EN L1_max30102_WB(REG_INTR_ENABLE_2,0x00);// L1_max30102_WB(REG_FIFO_WR_PTR,0x00);//FIFO_WR_PTR[4:0] L1_max30102_WB(REG_OVF_COUNTER,0x00);//OVF_COUNTER[4:0] L1_max30102_WB(REG_FIFO_RD_PTR,0x00);//FIFO_RD_PTR[4:0] L1_max30102_WB(REG_FIFO_CONFIG,0x0f);//sample avg = 1, fifo rollover=false, fifo almost full = 17 L1_max30102_WB(REG_MODE_CONFIG,0x03);//0x02 for Red only, 0x03 for SpO2 mode 0x07 multimode LED L1_max30102_WB(REG_SPO2_CONFIG,0x27); // SPO2_ADC range = 4096nA, SPO2 sample rate (50 Hz), LED pulseWidth (400uS) L1_max30102_WB(REG_LED1_PA,0x32);//Choose value for ~ 10mA for LED1 L1_max30102_WB(REG_LED2_PA,0x32);// Choose value for ~ 10mA for LED2 L1_max30102_WB(REG_PILOT_PA,0x7f);// Choose value for ~ 25mA for Pilot LED } void MAX30102_Configbbb(void) { u8 id1,id2,rr = 0xE5; L1_max30102_WB(REG_MODE_CONFIG, 0x40); Lc_delay_ms(200); //read and clear statu id1= IIC_Read_Byte(MAX30102_Device_address,REG_REV_ID); id2= IIC_Read_Byte(MAX30102_Device_address,REG_PART_ID); ///printf("\r\nMAX30102_Config %x %x \r\n",(int)id1,(int)id2); printf("\r\nMAX30102_Config %X %X %X \r\n",(int)rr,(int)id1,(int)id2); L1_max30102_WB(REG_INTR_ENABLE_1,0x00);//// L1_max30102_WB(REG_INTR_ENABLE_1,0xc0);//// INTR setting L1_max30102_WB(REG_INTR_ENABLE_2,0x00);// ///清空 L1_max30102_WB(REG_FIFO_WR_PTR,0x00);//FIFO_WR_PTR[4:0] L1_max30102_WB(REG_OVF_COUNTER,0x00);//OVF_COUNTER[4:0] L1_max30102_WB(REG_FIFO_RD_PTR,0x00);//FIFO_RD_PTR[4:0] L1_max30102_WB(REG_FIFO_CONFIG,0x0f);//sample avg = 1, fifo rollover=false, fifo almost full = 17 L1_max30102_WB(REG_MODE_CONFIG,0x03);//0x02 for Red only, 0x03 for SpO2 mode 0x07 multimode LED L1_max30102_WB(REG_SPO2_CONFIG,0x2B); // //SPO2_ADC range = 4096nA, 200Hz, LED pulseWidth (411uS) ,18bit L1_max30102_WB(REG_LED1_PA,0x40);//Choose value for ~ 10mA for LED1 L1_max30102_WB(REG_LED2_PA,0x40);// Choose value for ~ 10mA for LED2 L1_max30102_WB(REG_PILOT_PA,0x01);// Choose value for ~ 25mA for Pilot LED L1_max30102_WB(REG_TEMP_CONFIG,1); } void MAX30102_Config222(void) { u8 id1,id2,rr = 0xE5; L1_max30102_WB(REG_MODE_CONFIG, 0x40); Lc_delay_ms(200); //read and clear statu id1= IIC_Read_Byte(MAX30102_Device_address,REG_REV_ID); id2= IIC_Read_Byte(MAX30102_Device_address,REG_PART_ID); ///printf("\r\nMAX30102_Config %x %x \r\n",(int)id1,(int)id2); printf("\r\nMAX30102_Config %X %X %X \r\n",(int)rr,(int)id1,(int)id2); L1_max30102_WB(REG_INTR_ENABLE_1,0x00);//// L1_max30102_WB(REG_INTR_ENABLE_1,0xc0);//// INTR setting L1_max30102_WB(REG_INTR_ENABLE_2,0x00);// L1_max30102_WB(REG_FIFO_WR_PTR,0x00);//FIFO_WR_PTR[4:0] L1_max30102_WB(REG_OVF_COUNTER,0x00);//OVF_COUNTER[4:0] L1_max30102_WB(REG_FIFO_RD_PTR,0x00);//FIFO_RD_PTR[4:0] L1_max30102_WB(REG_FIFO_CONFIG,0x0f);//sample avg = 1, fifo rollover=false, fifo almost full = 17 L1_max30102_WB(REG_MODE_CONFIG,0x03);//0x02 for Red only, 0x03 for SpO2 mode 0x07 multimode LED L1_max30102_WB(REG_SPO2_CONFIG,0x27); // SPO2_ADC range = 4096nA, SPO2 sample rate (50 Hz), LED pulseWidth (400uS) L1_max30102_WB(REG_LED1_PA,0x32);//Choose value for ~ 10mA for LED1 L1_max30102_WB(REG_LED2_PA,0x32);// Choose value for ~ 10mA for LED2 L1_max30102_WB(REG_PILOT_PA,0x7f);// Choose value for ~ 25mA for Pilot LED L1_max30102_WB(REG_TEMP_CONFIG,1); } uint32 un_temp; int i=0; u8 m,s,s2; void max30102_read_fifo22(void) { } void max30102_read_fifo(void) { /************** ts_max30102.fifo_red=0; ts_max30102.fifo_ir=0; for(i=0;i<6;i++) { ts_max30102.d[i]=0; } printf("\r\n"); for(m = 0;m<=0x12;m ++) { s=IIC_Read_Byte(MAX30102_Device_address,m); printf("\r\nreg(%2x %d) = %2X %d ",(int)m,(int)m,(int)s,(u16)s); } printf("\r\n"); *************/ //read and clear statu s= IIC_Read_Byte(MAX30102_Device_address,REG_INTR_STATUS_1); // s=0x12; s2= IIC_Read_Byte(MAX30102_Device_address,REG_INTR_STATUS_2); /// printf("\r\nsta %X %X %X --",(int)0xAA,(int)s,(int)s2); s= IIC_Read_Byte(MAX30102_Device_address,REG_TEMP_INTR); // s=0x12; s2= IIC_Read_Byte(MAX30102_Device_address,REG_TEMP_FRAC); /// printf(" tmp %2X %2X %d.%d",(int)s,(int)s2,(int)s,(int)s2); ts_max30102.d[0]=REG_FIFO_DATA; L1_max30102_Read_Array(REG_FIFO_DATA,ts_max30102.d,6); /******** printf("fifo :%2X %2X %2X %2X %2X %2X ", (int)ts_max30102.d[0],(int)ts_max30102.d[1],(int)ts_max30102.d[2], (int)ts_max30102.d[3],(int)ts_max30102.d[4],(int)ts_max30102.d[5]); for(i=0;i<6;i++) { ts_max30102.d[i]=0x40+i; } printf("fifo :%2X %2X %2X %2X %2X %2X ", (int)ts_max30102.d[0],(int)ts_max30102.d[1],(int)ts_max30102.d[2], (int)ts_max30102.d[3],(int)ts_max30102.d[4],(int)ts_max30102.d[5]); *******/ un_temp=ts_max30102.d[0]; ts_max30102.fifo_red=un_temp<<16; un_temp=ts_max30102.d[1]; un_temp<<=8; ts_max30102.fifo_red|=un_temp; un_temp=ts_max30102.d[2]; // un_temp>>=2; ts_max30102.fifo_red|=un_temp; un_temp=ts_max30102.d[3]; ts_max30102.fifo_ir = un_temp<<16; un_temp=ts_max30102.d[4]; un_temp<<=8; ts_max30102.fifo_ir|=un_temp; un_temp=ts_max30102.d[5]; /// un_temp>>=2; ts_max30102.fifo_ir|=un_temp; ts_max30102.u16out_c = D_2uc_u16(ts_max30102.d[2],ts_max30102.d[5]); L1_uartD_sendulhex(ts_max30102.fifo_red); /// Lc_delay_ms(1); L1_uartD_senduc('R'); L1_uartD_sendulhex(ts_max30102.fifo_ir); // if(ts_max30102.fifo_ir<=10000) // { // ts_max30102.fifo_ir=0; // } // if(ts_max30102.fifo_red<=10000) // { // ts_max30102.fifo_red=0; // } // USART_SendData(USART_PORT,ts_max30102.fifo_red); // while (USART_GetFlag Status(USART_PORT, USART_FLAG_TXE) == RESET); // printf("%d %d\r\n",ts_max30102.fifo_red,ts_max30102.fifo_ir); // Delay_ms(100); } float max30102_getSpO2(float *ir_input_data,float *red_input_data,uint16_t cache_nums) { float ir_max=*ir_input_data,ir_min=*ir_input_data; float red_max=*red_input_data,red_min=*red_input_data; float R; uint16_t i; for(i=1;i*(ir_input_data+i)) { ir_min=*(ir_input_data+i); } if(red_max<*(red_input_data+i)) { red_max=*(red_input_data+i); } if(red_min>*(red_input_data+i)) { red_min=*(red_input_data+i); } } R=((ir_max+ir_min)*(red_max-red_min))/((red_max+red_min)*(ir_max-ir_min)); return ((-45.060)*R*R + 30.354*R + 94.845); }