找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 13233|回复: 11
收起左侧

max30100血氧传感器开发资料 附arduino和stm32源码

[复制链接]
ID:252774 发表于 2017-11-23 18:30 | 显示全部楼层 |阅读模式
本内容包括MAX30100的官方技术手册以及驱动代码
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.
0.png 0.png
0.png

单片机源程序如下:
  1. /*
  2. Arduino-MAX30100 oximetry / heart rate integrated sensor library
  3. Copyright (C) 2016  OXullo Intersecans <x@brainrapers.org>

  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.

  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. GNU General Public License for more details.

  12. You should have received a copy of the GNU General Public License
  13. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  14. */

  15. //#include <Wire.h>

  16. #include "MAX30100.h"
  17. #include "usart.h"
  18. #include "delay.h"
  19. #include "myiic.h"

  20. uint16_t rawIRValue;
  21. uint16_t rawRedValue;

  22. void max_begin()//void MAX30100::begin()
  23. {
  24. //          I2C_GPIO_Config();
  25. //          I2C_Mode_Config();
  26. //    Wire.begin();
  27. //    Wire.setClock(I2C_BUS_SPEED);
  28.                 IIC_Init();
  29.     setMode(DEFAULT_MODE);        //往地址0x06的寄存器写0x02(仅打开心率测量模块)
  30.     setLedsPulseWidth(DEFAULT_PULSE_WIDTH);        //往地址0x07的寄存器写0x03(16位AD转换,脉冲宽度1.6ms)
  31.     setSamplingRate(DEFAULT_SAMPLING_RATE);        //往地址0x07的寄存器写0x01(设置采样率为100)
  32.     setLedsCurrent(DEFAULT_IR_LED_CURRENT, DEFAULT_RED_LED_CURRENT);        //往地址0x09的寄存器写0xff(控制Red_led,IR_led电流各为50ma)
  33. //    setHighresModeEnabled(true);
  34.           setHighresModeEnabled(1); //使能血氧饱和度的ADC的分辨率为16位,1.6ms LED脉冲宽度

  35. }

  36. void setMode(Mode mode)//void MAX30100::setMode(Mode mode)
  37. {
  38. //    writeRegister(MAX30100_REG_MODE_CONFIGURATION, mode);
  39.            Write_One_Byte(MAX30100_REG_MODE_CONFIGURATION, mode);
  40. //        printf("%d\r\n",Write_One_Byte(MAX30100_REG_MODE_CONFIGURATION, mode));
  41. }

  42. void setLedsPulseWidth(LEDPulseWidth ledPulseWidth)//void MAX30100::setLedsPulseWidth(LEDPulseWidth ledPulseWidth)
  43. {
  44. //    uint8_t previous = readRegister(MAX30100_REG_SPO2_CONFIGURATION);
  45. //    writeRegister(MAX30100_REG_SPO2_CONFIGURATION, (previous & 0xfc) | ledPulseWidth);
  46.           uint8_t previous;  previous=Read_One_Byte(MAX30100_REG_SPO2_CONFIGURATION);        //reg 0x07
  47.                 printf("Read_One_Byte(0x07); =  0x%x \n", previous);        
  48.     Write_One_Byte(MAX30100_REG_SPO2_CONFIGURATION, (previous & 0xfc) | ledPulseWidth);        //reg 0x07 w
  49. }

  50. void setSamplingRate(SamplingRate samplingRate)//void MAX30100::setSamplingRate(SamplingRate samplingRate)
  51. {
  52. //    uint8_t previous = readRegister(MAX30100_REG_SPO2_CONFIGURATION);
  53. //    writeRegister(MAX30100_REG_SPO2_CONFIGURATION, (previous & 0xe3) | (samplingRate << 2));
  54.                         uint8_t previous; previous=Read_One_Byte(MAX30100_REG_SPO2_CONFIGURATION);        //reg 0x07
  55.             Write_One_Byte(MAX30100_REG_SPO2_CONFIGURATION, (previous & 0xe3) | (samplingRate << 2));        //reg 0x07 w

  56. }

  57. void setLedsCurrent(LEDCurrent irLedCurrent, LEDCurrent redLedCurrent)//void MAX30100::setLedsCurrent(LEDCurrent irLedCurrent, LEDCurrent redLedCurrent)
  58. {
  59. //    writeRegister(MAX30100_REG_LED_CONFIGURATION, redLedCurrent << 4 | irLedCurrent);
  60.                         Write_One_Byte(MAX30100_REG_LED_CONFIGURATION, redLedCurrent << 4 | irLedCurrent);        //reg 0x09
  61. }

  62. void setHighresModeEnabled(u8 enabled)//void MAX30100::setHighresModeEnabled(bool enabled)
  63. {
  64. //    uint8_t previous = readRegister(MAX30100_REG_SPO2_CONFIGURATION);
  65. //    if (enabled) {
  66. //        writeRegister(MAX30100_REG_SPO2_CONFIGURATION, previous | MAX30100_SPC_SPO2_HI_RES_EN);
  67. //    } else {
  68. //        writeRegister(MAX30100_REG_SPO2_CONFIGURATION, previous & ~MAX30100_SPC_SPO2_HI_RES_EN);
  69. //    }
  70.            uint8_t previous;
  71.            previous=Read_One_Byte(MAX30100_REG_SPO2_CONFIGURATION);
  72.            if (enabled) {
  73.         Write_One_Byte(MAX30100_REG_SPO2_CONFIGURATION, previous | MAX30100_SPC_SPO2_HI_RES_EN);
  74.     } else {
  75.         Write_One_Byte(MAX30100_REG_SPO2_CONFIGURATION, previous & ~MAX30100_SPC_SPO2_HI_RES_EN);
  76.     }
  77. }

  78. void update()//void MAX30100::update()
  79. {
  80.     readFifoData();
  81. }

  82. void readFifoData(void)//void MAX30100::readFifoData()
  83. {
  84. //        int i;
  85.     uint8_t buffer[4];

  86.     Buff_Read(MAX30100_REG_FIFO_DATA,buffer, 4);

  87.     // Warning: the values are always left-aligned
  88.     rawIRValue = (buffer[0] << 8) | buffer[1];
  89.     rawRedValue = (buffer[2] << 8) | buffer[3];
  90.         
  91.         printf("rawIRValue =  %d \n",rawIRValue);
  92.         printf("rawRedValue =  %d \n",rawRedValue);
  93. //        for(i=0; i<4; i++)
  94. //        {
  95. //                printf("buffer[%d] =  %d \n",i, buffer[i]);
  96. //        }
  97. }

  98. u8 Write_One_Byte(u8 addr,u8 data)
  99. {
  100.          IIC_Start();
  101.     IIC_Send_Byte(0xAE);        //发送地址+写命令
  102.     if(IIC_Wait_Ack())          //等待ACK
  103.     {
  104.         goto RESTATE;
  105.     }
  106.     IIC_Send_Byte(addr);         //发送寄存器地址
  107.     if(IIC_Wait_Ack())          //等待ACK
  108.     {
  109.         goto RESTATE;
  110.     }
  111.     IIC_Send_Byte(data);        //发送数据
  112.     if(IIC_Wait_Ack())          //等待ACK
  113.     {
  114.         goto RESTATE;;
  115.     }

  116.     IIC_Stop();
  117.     return 1;
  118.          
  119. RESTATE:        
  120.     IIC_Stop();
  121.     return 0;
  122. }
  123. u8 Read_One_Byte(u8 addr)
  124. {
  125.    uint8_t res;
  126.     IIC_Start();
  127.     IIC_Send_Byte(0xAE); //发送期间地址+写命令
  128.     if(IIC_Wait_Ack())          //等待ACK
  129.     {
  130.         goto RESTATE;
  131.     }
  132.     IIC_Send_Byte(addr);         //发送寄存器地址
  133.     if(IIC_Wait_Ack())          //等待ACK
  134.     {
  135.         goto RESTATE;
  136.     }
  137.       IIC_Start();   
  138.     IIC_Send_Byte(0xAF);  //发送器件地址+读命令
  139.     if(IIC_Wait_Ack())          //等待ACK
  140.     {
  141.         goto RESTATE;
  142.     }
  143.     res=IIC_Read_Byte(0);       //
  144.     IIC_Stop();                 //
  145.     return res;
  146.      
  147. RESTATE:        
  148.     IIC_Stop();
  149.     return 0;
  150. }

  151. u8 Buff_Read(u8 address,u8 *buf, u8 len)  //读取特定地址寄存器里面特定长度的数据
  152. {
  153.   IIC_Start();
  154. ……………………

  155. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码


arduino源程序如下:
  1. /*
  2. Arduino-MAX30100 oximetry / heart rate integrated sensor library
  3. Copyright (C) 2016  OXullo Intersecans <x@brainrapers.org>

  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.

  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. GNU General Public License for more details.

  12. You should have received a copy of the GNU General Public License
  13. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  14. */

  15. #include <Wire.h>

  16. #include "MAX30100.h"

  17. MAX30100::MAX30100()
  18. {
  19. }

  20. void MAX30100::begin()
  21. {
  22.     Wire.begin();
  23.     Wire.setClock(I2C_BUS_SPEED);

  24.     setMode(DEFAULT_MODE);
  25.     setLedsPulseWidth(DEFAULT_PULSE_WIDTH);
  26.     setSamplingRate(DEFAULT_SAMPLING_RATE);
  27.     setLedsCurrent(DEFAULT_IR_LED_CURRENT, DEFAULT_RED_LED_CURRENT);
  28.     setHighresModeEnabled(true);
  29. }

  30. void MAX30100::setMode(Mode mode)
  31. {
  32.     writeRegister(MAX30100_REG_MODE_CONFIGURATION, mode);
  33. }

  34. void MAX30100::setLedsPulseWidth(LEDPulseWidth ledPulseWidth)
  35. {
  36.     uint8_t previous = readRegister(MAX30100_REG_SPO2_CONFIGURATION);
  37.     writeRegister(MAX30100_REG_SPO2_CONFIGURATION, (previous & 0xfc) | ledPulseWidth);
  38. }

  39. void MAX30100::setSamplingRate(SamplingRate samplingRate)
  40. {
  41.     uint8_t previous = readRegister(MAX30100_REG_SPO2_CONFIGURATION);
  42.     writeRegister(MAX30100_REG_SPO2_CONFIGURATION, (previous & 0xe3) | (samplingRate << 2));
  43. }

  44. void MAX30100::setLedsCurrent(LEDCurrent irLedCurrent, LEDCurrent redLedCurrent)
  45. {
  46.     writeRegister(MAX30100_REG_LED_CONFIGURATION, redLedCurrent << 4 | irLedCurrent);
  47. }

  48. void MAX30100::setHighresModeEnabled(bool enabled)
  49. {
  50.     uint8_t previous = readRegister(MAX30100_REG_SPO2_CONFIGURATION);
  51.     if (enabled) {
  52.         writeRegister(MAX30100_REG_SPO2_CONFIGURATION, previous | MAX30100_SPC_SPO2_HI_RES_EN);
  53.     } else {
  54.         writeRegister(MAX30100_REG_SPO2_CONFIGURATION, previous & ~MAX30100_SPC_SPO2_HI_RES_EN);
  55.     }
  56. }

  57. void MAX30100::update()
  58. {
  59.     readFifoData();
  60. }

  61. uint8_t MAX30100::readRegister(uint8_t address)
  62. {
  63.     Wire.beginTransmission(MAX30100_I2C_ADDRESS);
  64.    
  65. …………
  66. …………
  67. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
max3010血氧传感器.rar (1.78 MB, 下载次数: 300)
回复

使用道具 举报

ID:258140 发表于 2017-12-6 13:33 | 显示全部楼层
我下载完了文件打不开这个压缩软件,应该用什么压缩软件
回复

使用道具 举报

ID:258140 发表于 2017-12-6 13:34 | 显示全部楼层
下载了这个资源,但是却打不开这个压缩文件,用什么压缩软件可以打开
回复

使用道具 举报

ID:309165 发表于 2018-4-23 20:32 | 显示全部楼层
这代码,全都挤到mian.c里面了,
回复

使用道具 举报

ID:252000 发表于 2018-4-29 20:30 | 显示全部楼层
求下載
回复

使用道具 举报

ID:330333 发表于 2018-5-15 20:52 | 显示全部楼层
求下载
回复

使用道具 举报

ID:284903 发表于 2018-5-26 18:31 | 显示全部楼层
楼主怎么接线?
回复

使用道具 举报

ID:284903 发表于 2018-5-26 19:37 | 显示全部楼层
这玩意为什么arduino源码里面没有ino文件?怎么用?
回复

使用道具 举报

ID:284903 发表于 2018-5-26 20:26 | 显示全部楼层
这根本不是源码,是MAX30100的库,都没看到setup和loop函数,楼主贴下如何?
回复

使用道具 举报

ID:349935 发表于 2018-6-11 23:50 | 显示全部楼层
这个书法感觉像是库文件啊
回复

使用道具 举报

ID:373340 发表于 2018-7-17 15:29 | 显示全部楼层
longzhen777 发表于 2017-12-6 13:34
**** 作者被禁止或删除 内容自动屏蔽 ****

360压缩
回复

使用道具 举报

ID:440455 发表于 2018-12-6 20:41 | 显示全部楼层
代码可以直接使用吗
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表