max30102c语言程序,MAX30102基于STM32F103C8T6的程序源码
单片机源程序如下:
/** file main.cpp ******************************************************
*
* Project: STM32F103C8T6+MAX30102
* Edited by Anning
* ------------------------------------------------------------------------- */
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
/*!mainpage Main Page
*
* section intro_sec Introduction
*
* This is the code documentation for the MAXREFDES117# subsystem reference design.
*
* The Files page contains the File List page and the Globals page.
*
* The Globals page contains the Functions, Variables, and Macros sub-pages.
*
* image html MAXREFDES117_Block_Diagram.png "MAXREFDES117# System Block Diagram"
*
* image html MAXREFDES117_firmware_Flowchart.png "MAXREFDES117# Firmware Flowchart"
*
*/
#include "stm32f103c8t6.h"
#include "mbed.h"
#include "algorithm.h"
#include "MAX30102.h"
#define MAX_BRIGHTNESS 255
uint32_t aun_ir_buffer[500]; //IR LED sensor data
int32_t n_ir_buffer_length; //data length
uint32_t aun_red_buffer[500]; //Red LED sensor data
int32_t n_sp02; //SPO2 value
int8_t ch_spo2_valid; //indicator to show if the SP02 calculation is valid
int32_t n_heart_rate; //heart rate value
int8_t ch_hr_valid; //indicator to show if the heart rate calculation is valid
uint8_t uch_dummy;
Serial pc(SERIAL_TX, SERIAL_RX); //initializes the serial port, TX-PA2, RX-PA3
PwmOut pwmled(PB_3); //initializes the pwm output PB3 that connects to the LED
DigitalIn INT(PB_7); //pin PB7 connects to the interrupt output pin of the MAX30102
DigitalOut led(PC_13); //PC13 connects to the on board user LED
// the setup routine runs once when you press reset:
int main() {
uint32_t un_min, un_max, un_prev_data; //variables to calculate the on-board LED brightness that reflects the heartbeats
int i;
int32_t n_brightness;
float f_temp;
maxim_max30102_reset(); //resets the MAX30102
// initialize serial communication at 115200 bits per second:
pc.baud(115200);
pc.format(8,SerialBase::None,1);
wait(1);
//read and clear status register
maxim_max30102_read_reg(0,&uch_dummy);
//wait until the user presses a key
// while(pc.readable()==0)
// {
// pc.printf("x1B[2J"); //clear terminal program screen
// pc.printf("Press any key to start conversionnr");
// wait(1);
// }
// uch_dummy=getchar();
maxim_max30102_init(); //initializes the MAX30102
n_brightness=0;
un_min=0x3FFFF;
un_max=0;
n_ir_buffer_length=500; //buffer length of 100 stores 5 seconds of samples running at 100sps
//read the first 500 samples, and determine the signal range
for(i=0;i{
while(INT.read()==1); //wait until the interrupt pin asserts
maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i)); //read from MAX30102 FIFO
if(un_min>aun_red_buffer[i])
un_min=aun_red_buffer[i]; //update signal min
if(un_maxun_max=aun_red_buffer[i]; //update signal max
pc.printf("red=");
pc.printf("%i", aun_red_buffer[i]);
pc.printf(", ir=");
pc.printf("%inr", aun_ir_buffer[i]);
}
un_prev_data=aun_red_buffer[i];
//calculate heart rate and SpO2 after first 500 samples (first 5 seconds of samples)
maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid);
//Continuously taking samples from MAX30102. Heart rate and SpO2 are calculated every 1 second
while(1)
{
i=0;
un_min=0x3FFFF;
un_max=0;
//dumping the first 100 sets of samples in the memory and shift the last 400 sets of samples to the top
for(i=100;i<500;i++)
{
aun_red_buffer[i-100]=aun_red_buffer[i];
aun_ir_buffer[i-100]=aun_ir_buffer[i];
//update the signal min and max
if(un_min>aun_red_buffer[i])
un_min=aun_red_buffer[i];
if(un_maxun_max=aun_red_buffer[i];
}
//take 100 sets of samples before calculating the heart rate.
for(i=400;i<500;i++)
{
un_prev_data=aun_red_buffer[i-1];
while(INT.read()==1);
maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i));
if(aun_red_buffer[i]>un_prev_data)//just to determine the brightness of LED according to the deviation of adjacent two AD data
{
f_temp=aun_red_buffer[i]-un_prev_data;
f_temp/=(un_max-un_min);
f_temp*=MAX_BRIGHTNESS;
n_brightness-=(int)f_temp;
if(n_brightness<0)
n_brightness=0;
}
else
{
f_temp=un_prev_data-aun_red_buffer[i];
f_temp/=(un_max-un_min);
f_temp*=MAX_BRIGHTNESS;
n_brightness+=(int)f_temp;
if(n_brightness>MAX_BRIGHTNESS)
n_brightness=MAX_BRIGHTNESS;
}
pwmled.write(1-(float)n_brightness/256);//pwm control led brightness
if(n_brightness<120)
led=1;
else
led=0;
//send samples and calculation result to terminal program through UART
pc.printf("red=");
pc.printf("%i", aun_red_buffer[i]);
pc.printf(", ir=");
pc.printf("%i", aun_ir_buffer[i]);
pc.printf(", HR=%i, ", n_heart_rate);
pc.printf("HRvalid=%i, ", ch_hr_valid);
pc.printf("SpO2=%i, ", n_sp02);
pc.printf("SPO2Valid=%inr", ch_spo2_valid);
}
maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid);
}
}
max30102c语言程序,MAX30102基于STM32F103C8T6的程序源码相关推荐
- 易语言mysql数据同步程序_易语言mssql和mysql数据自动同步源码
易语言mssql和mysql数据自动同步源码 易语言mssql和mysql数据自动同步源码 系统结构:RefreshTask,ComputeEndTime,ComputeOneTime,Compute ...
- 为什么C/C++程序员都要阅读Redis源码之:Redis学习事件驱动设计
0. 为什么我说C/C++程序员都要阅读Redis源码 主要原因就是『简洁』.如果你用源码编译过Redis,你会发现十分轻快,一步到位.其他语言的开发者可能不会了解这种痛,作为C/C++程序员,如果你 ...
- c++ 多线程 类成员函数_为什么我说C/C++程序员都要阅读Redis源码之:通过Redis学习事件驱动设计
0. 为什么我说C/C++程序员都要阅读Redis源码 主要原因就是『简洁』.如果你用源码编译过Redis,你会发现十分轻快,一步到位.其他语言的开发者可能不会了解这种痛,作为C/C++程序员,如果你 ...
- Thinkphp5内核大型程序员交流博客系统源码
介绍: Thinkphp5内核大型程序员交流博客系统源码 网盘下载地址: http://kekewl.cc/qGKM757akv40 图片:
- 校园跑腿微信小程序跑腿同学带直播新版源码
校园跑腿微信小程序跑腿同学带直播新版源码 适用类型 微信小程序 测试环境:系统环境:CentOS Linux 7.6.1810 (Core).运行环境:宝塔 Linux v7.0.3(专业版).网站环 ...
- 微信小程序支付功能-服务器端实现(附源码)
实现了小程序最新的V3版本支付功能, 包括:支付.支付通知.退款.退款通知. 服务器端使用java开发,springboot框架 源码链接在评论中 微信小程序支付功能-服务器端实现(附源码)_哔哩哔哩 ...
- 为什么C/C++程序员一定要阅读redis源码?腾讯面试教你做人【linux服务器开发】
为什么C/C++程序员一定要阅读redis源码?腾讯面试教你做人[linux服务器开发] 专注于服务器后台开发,包括C/C++,Linux,Nginx,ZeroMQ,MySQL,Redis,fastd ...
- WoShop跨境电商USDT支付语言插件全开源无加密商城源码
WoShop跨境电商USDT支付语言插件全开源无加密商城源码 基于现场直播+购物模式,用户可以"边看边买"现场直播商城平台,全终端支持,统一管理后台,传播更强,管理更方便,支持私有 ...
- 计算机毕业设计Java基于的智慧小区(源码+系统+mysql数据库+lW文档)
计算机毕业设计Java基于的智慧小区(源码+系统+mysql数据库+lW文档) 计算机毕业设计Java基于的智慧小区(源码+系统+mysql数据库+lW文档) 本源码技术栈: 项目架构:B/S架构 开 ...
- 基于Java毕业设计知识库系统源码+系统+mysql+lw文档+部署软件
基于Java毕业设计知识库系统源码+系统+mysql+lw文档+部署软件 基于Java毕业设计知识库系统源码+系统+mysql+lw文档+部署软件 本源码技术栈: 项目架构:B/S架构 开发语言:Ja ...
最新文章
- css层叠上下文和层叠顺序
- OpenCASCADE:Direct3D CSharp 示例
- C++ class实现链栈(完整代码)
- mysql调优_MYSQL企业常用架构与调优经验分享
- 利用win7系统自身修复还原功能
- 笔记 编写可读性代码的艺术
- FAQ from CSDN
- 看完这篇还不了解 Nginx,那我就哭了!
- Ubuntu 查看 Cuda 及 版本
- 浅谈数据中心白盒交换机开发
- Ring3触发BSOD代码实现及内核逆向分析
- 社工必备查询网址汇总
- 2021-06-03TunePat Amazon Video Downloader使用教程:如何下载电影和电视节目
- vue - vue项目使用BOS (百度云对象存储)上传文件
- 同一个元素绑定多个onclick事件
- 汉堡按钮的制作以及其中的问题
- 算法设计与分析第二章作业
- 如何在Android上使用音乐流服务作为警报
- html5手机截屏,手机的这6种截屏方法,你用过几种?
- BIST(build_in selftest)介绍