|
本內(nèi)容包括MAX30100的官方技術(shù)手冊以及驅(qū)動代碼
General Description
The MAX30100 is an integrated pulse oximetry and heart-rate monitor sensor solution. It combines two LEDs, a photodetector, optimized optics, and low-noise analog signal processing to detect pulse oximetry and heart-rate
signals.
The MAX30100 operates from 1.8V and 3.3V power sup-plies and can be powered down through software with negligible standby current, permitting the power supply to emain connected at all times.
單片機源程序如下:
- /*
- Arduino-MAX30100 oximetry / heart rate integrated sensor library
- Copyright (C) 2016 OXullo Intersecans <x@brainrapers.org>
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- //#include <Wire.h>
- #include "MAX30100.h"
- #include "usart.h"
- #include "delay.h"
- #include "myiic.h"
- uint16_t rawIRValue;
- uint16_t rawRedValue;
- void max_begin()//void MAX30100::begin()
- {
- // I2C_GPIO_Config();
- // I2C_Mode_Config();
- // Wire.begin();
- // Wire.setClock(I2C_BUS_SPEED);
- IIC_Init();
- setMode(DEFAULT_MODE); //往地址0x06的寄存器寫0x02(僅打開心率測量模塊)
- setLedsPulseWidth(DEFAULT_PULSE_WIDTH); //往地址0x07的寄存器寫0x03(16位AD轉(zhuǎn)換,脈沖寬度1.6ms)
- setSamplingRate(DEFAULT_SAMPLING_RATE); //往地址0x07的寄存器寫0x01(設(shè)置采樣率為100)
- setLedsCurrent(DEFAULT_IR_LED_CURRENT, DEFAULT_RED_LED_CURRENT); //往地址0x09的寄存器寫0xff(控制Red_led,IR_led電流各為50ma)
- // setHighresModeEnabled(true);
- setHighresModeEnabled(1); //使能血氧飽和度的ADC的分辨率為16位,1.6ms LED脈沖寬度
- }
- void setMode(Mode mode)//void MAX30100::setMode(Mode mode)
- {
- // writeRegister(MAX30100_REG_MODE_CONFIGURATION, mode);
- Write_One_Byte(MAX30100_REG_MODE_CONFIGURATION, mode);
- // printf("%d\r\n",Write_One_Byte(MAX30100_REG_MODE_CONFIGURATION, mode));
- }
- void setLedsPulseWidth(LEDPulseWidth ledPulseWidth)//void MAX30100::setLedsPulseWidth(LEDPulseWidth ledPulseWidth)
- {
- // uint8_t previous = readRegister(MAX30100_REG_SPO2_CONFIGURATION);
- // writeRegister(MAX30100_REG_SPO2_CONFIGURATION, (previous & 0xfc) | ledPulseWidth);
- uint8_t previous; previous=Read_One_Byte(MAX30100_REG_SPO2_CONFIGURATION); //reg 0x07
- printf("Read_One_Byte(0x07); = 0x%x \n", previous);
- Write_One_Byte(MAX30100_REG_SPO2_CONFIGURATION, (previous & 0xfc) | ledPulseWidth); //reg 0x07 w
- }
- void setSamplingRate(SamplingRate samplingRate)//void MAX30100::setSamplingRate(SamplingRate samplingRate)
- {
- // uint8_t previous = readRegister(MAX30100_REG_SPO2_CONFIGURATION);
- // writeRegister(MAX30100_REG_SPO2_CONFIGURATION, (previous & 0xe3) | (samplingRate << 2));
- uint8_t previous; previous=Read_One_Byte(MAX30100_REG_SPO2_CONFIGURATION); //reg 0x07
- Write_One_Byte(MAX30100_REG_SPO2_CONFIGURATION, (previous & 0xe3) | (samplingRate << 2)); //reg 0x07 w
- }
- void setLedsCurrent(LEDCurrent irLedCurrent, LEDCurrent redLedCurrent)//void MAX30100::setLedsCurrent(LEDCurrent irLedCurrent, LEDCurrent redLedCurrent)
- {
- // writeRegister(MAX30100_REG_LED_CONFIGURATION, redLedCurrent << 4 | irLedCurrent);
- Write_One_Byte(MAX30100_REG_LED_CONFIGURATION, redLedCurrent << 4 | irLedCurrent); //reg 0x09
- }
- void setHighresModeEnabled(u8 enabled)//void MAX30100::setHighresModeEnabled(bool enabled)
- {
- // uint8_t previous = readRegister(MAX30100_REG_SPO2_CONFIGURATION);
- // if (enabled) {
- // writeRegister(MAX30100_REG_SPO2_CONFIGURATION, previous | MAX30100_SPC_SPO2_HI_RES_EN);
- // } else {
- // writeRegister(MAX30100_REG_SPO2_CONFIGURATION, previous & ~MAX30100_SPC_SPO2_HI_RES_EN);
- // }
- uint8_t previous;
- previous=Read_One_Byte(MAX30100_REG_SPO2_CONFIGURATION);
- if (enabled) {
- Write_One_Byte(MAX30100_REG_SPO2_CONFIGURATION, previous | MAX30100_SPC_SPO2_HI_RES_EN);
- } else {
- Write_One_Byte(MAX30100_REG_SPO2_CONFIGURATION, previous & ~MAX30100_SPC_SPO2_HI_RES_EN);
- }
- }
- void update()//void MAX30100::update()
- {
- readFifoData();
- }
- void readFifoData(void)//void MAX30100::readFifoData()
- {
- // int i;
- uint8_t buffer[4];
- Buff_Read(MAX30100_REG_FIFO_DATA,buffer, 4);
- // Warning: the values are always left-aligned
- rawIRValue = (buffer[0] << 8) | buffer[1];
- rawRedValue = (buffer[2] << 8) | buffer[3];
-
- printf("rawIRValue = %d \n",rawIRValue);
- printf("rawRedValue = %d \n",rawRedValue);
- // for(i=0; i<4; i++)
- // {
- // printf("buffer[%d] = %d \n",i, buffer[i]);
- // }
- }
- u8 Write_One_Byte(u8 addr,u8 data)
- {
- IIC_Start();
- IIC_Send_Byte(0xAE); //發(fā)送地址+寫命令
- if(IIC_Wait_Ack()) //等待ACK
- {
- goto RESTATE;
- }
- IIC_Send_Byte(addr); //發(fā)送寄存器地址
- if(IIC_Wait_Ack()) //等待ACK
- {
- goto RESTATE;
- }
- IIC_Send_Byte(data); //發(fā)送數(shù)據(jù)
- if(IIC_Wait_Ack()) //等待ACK
- {
- goto RESTATE;;
- }
-
- IIC_Stop();
- return 1;
-
- RESTATE:
- IIC_Stop();
- return 0;
- }
- u8 Read_One_Byte(u8 addr)
- {
- uint8_t res;
- IIC_Start();
- IIC_Send_Byte(0xAE); //發(fā)送期間地址+寫命令
- if(IIC_Wait_Ack()) //等待ACK
- {
- goto RESTATE;
- }
- IIC_Send_Byte(addr); //發(fā)送寄存器地址
- if(IIC_Wait_Ack()) //等待ACK
- {
- goto RESTATE;
- }
- IIC_Start();
- IIC_Send_Byte(0xAF); //發(fā)送器件地址+讀命令
- if(IIC_Wait_Ack()) //等待ACK
- {
- goto RESTATE;
- }
- res=IIC_Read_Byte(0); //
- IIC_Stop(); //
- return res;
-
- RESTATE:
- IIC_Stop();
- return 0;
- }
- u8 Buff_Read(u8 address,u8 *buf, u8 len) //讀取特定地址寄存器里面特定長度的數(shù)據(jù)
- {
- IIC_Start();
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
arduino源程序如下:
- /*
- Arduino-MAX30100 oximetry / heart rate integrated sensor library
- Copyright (C) 2016 OXullo Intersecans <x@brainrapers.org>
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include <Wire.h>
- #include "MAX30100.h"
- MAX30100::MAX30100()
- {
- }
- void MAX30100::begin()
- {
- Wire.begin();
- Wire.setClock(I2C_BUS_SPEED);
- setMode(DEFAULT_MODE);
- setLedsPulseWidth(DEFAULT_PULSE_WIDTH);
- setSamplingRate(DEFAULT_SAMPLING_RATE);
- setLedsCurrent(DEFAULT_IR_LED_CURRENT, DEFAULT_RED_LED_CURRENT);
- setHighresModeEnabled(true);
- }
- void MAX30100::setMode(Mode mode)
- {
- writeRegister(MAX30100_REG_MODE_CONFIGURATION, mode);
- }
- void MAX30100::setLedsPulseWidth(LEDPulseWidth ledPulseWidth)
- {
- uint8_t previous = readRegister(MAX30100_REG_SPO2_CONFIGURATION);
- writeRegister(MAX30100_REG_SPO2_CONFIGURATION, (previous & 0xfc) | ledPulseWidth);
- }
- void MAX30100::setSamplingRate(SamplingRate samplingRate)
- {
- uint8_t previous = readRegister(MAX30100_REG_SPO2_CONFIGURATION);
- writeRegister(MAX30100_REG_SPO2_CONFIGURATION, (previous & 0xe3) | (samplingRate << 2));
- }
- void MAX30100::setLedsCurrent(LEDCurrent irLedCurrent, LEDCurrent redLedCurrent)
- {
- writeRegister(MAX30100_REG_LED_CONFIGURATION, redLedCurrent << 4 | irLedCurrent);
- }
- void MAX30100::setHighresModeEnabled(bool enabled)
- {
- uint8_t previous = readRegister(MAX30100_REG_SPO2_CONFIGURATION);
- if (enabled) {
- writeRegister(MAX30100_REG_SPO2_CONFIGURATION, previous | MAX30100_SPC_SPO2_HI_RES_EN);
- } else {
- writeRegister(MAX30100_REG_SPO2_CONFIGURATION, previous & ~MAX30100_SPC_SPO2_HI_RES_EN);
- }
- }
- void MAX30100::update()
- {
- readFifoData();
- }
- uint8_t MAX30100::readRegister(uint8_t address)
- {
- Wire.beginTransmission(MAX30100_I2C_ADDRESS);
-
- …………
- …………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
max3010血氧傳感器.rar
(1.78 MB, 下載次數(shù): 303)
2017-11-23 21:20 上傳
點擊文件名下載附件
|
|