久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4764|回復: 4
打印 上一主題 下一主題
收起左側

stm32c8t6+MAX30102心率檢測源程序

[復制鏈接]
跳轉到指定樓層
樓主
ID:385235 發表于 2019-7-28 11:14 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
  1. #include "stm32f103c8t6.h"
  2. #include "mbed.h"
  3. #include "algorithm.h"
  4. #include "MAX30102.h"

  5. #define MAX_BRIGHTNESS 255

  6. uint32_t aun_ir_buffer[500]; //IR LED sensor data
  7. int32_t n_ir_buffer_length;    //data length
  8. uint32_t aun_red_buffer[500];    //Red LED sensor data
  9. int32_t n_sp02; //SPO2 value
  10. int8_t ch_spo2_valid;   //indicator to show if the SP02 calculation is valid
  11. int32_t n_heart_rate;   //heart rate value
  12. int8_t  ch_hr_valid;    //indicator to show if the heart rate calculation is valid
  13. uint8_t uch_dummy;

  14. Serial pc(SERIAL_TX, SERIAL_RX);    //initializes the serial port, TX-PA2, RX-PA3

  15. PwmOut pwmled(PB_3);  //initializes the pwm output PB3 that connects to the LED
  16. DigitalIn INT(PB_7);  //pin PB7 connects to the interrupt output pin of the MAX30102
  17. DigitalOut led(PC_13); //PC13 connects to the on board user LED


  18. // the setup routine runs once when you press reset:
  19. int main() {
  20.     uint32_t un_min, un_max, un_prev_data;  //variables to calculate the on-board LED brightness that reflects the heartbeats
  21.     int i;
  22.     int32_t n_brightness;
  23.     float f_temp;

  24.     maxim_max30102_reset(); //resets the MAX30102
  25.     // initialize serial communication at 115200 bits per second:
  26.     pc.baud(115200);
  27.     pc.format(8,SerialBase::None,1);
  28.     wait(1);

  29.     //read and clear status register
  30.     maxim_max30102_read_reg(0,&uch_dummy);

  31.     //wait until the user presses a key
  32. //    while(pc.readable()==0)
  33. //    {
  34. //        pc.printf("\x1B[2J");  //clear terminal program screen
  35. //        pc.printf("Press any key to start conversion\n\r");
  36. //        wait(1);
  37. //    }
  38. //    uch_dummy=getchar();

  39.     maxim_max30102_init();  //initializes the MAX30102


  40.     n_brightness=0;
  41.     un_min=0x3FFFF;
  42.     un_max=0;

  43.     n_ir_buffer_length=500; //buffer length of 100 stores 5 seconds of samples running at 100sps

  44.     //read the first 500 samples, and determine the signal range
  45.     for(i=0;i<n_ir_buffer_length;i++)
  46.     {
  47.         while(INT.read()==1);   //wait until the interrupt pin asserts

  48.         maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i));  //read from MAX30102 FIFO

  49.         if(un_min>aun_red_buffer[i])
  50.             un_min=aun_red_buffer[i];    //update signal min
  51.         if(un_max<aun_red_buffer[i])
  52.             un_max=aun_red_buffer[i];    //update signal max
  53.         pc.printf("red=");
  54.         pc.printf("%i", aun_red_buffer[i]);
  55.         pc.printf(", ir=");
  56.         pc.printf("%i\n\r", aun_ir_buffer[i]);
  57.     }
  58.     un_prev_data=aun_red_buffer[i];


  59.     //calculate heart rate and SpO2 after first 500 samples (first 5 seconds of samples)
  60.     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);

  61.     //Continuously taking samples from MAX30102.  Heart rate and SpO2 are calculated every 1 second
  62.     while(1)
  63.     {
  64.         i=0;
  65.         un_min=0x3FFFF;
  66.         un_max=0;

  67.         //dumping the first 100 sets of samples in the memory and shift the last 400 sets of samples to the top
  68.         for(i=100;i<500;i++)
  69.         {
  70.             aun_red_buffer[i-100]=aun_red_buffer[i];
  71.             aun_ir_buffer[i-100]=aun_ir_buffer[i];

  72.             //update the signal min and max
  73.             if(un_min>aun_red_buffer[i])
  74.             un_min=aun_red_buffer[i];
  75.             if(un_max<aun_red_buffer[i])
  76.             un_max=aun_red_buffer[i];
  77.         }

  78.         //take 100 sets of samples before calculating the heart rate.
  79.         for(i=400;i<500;i++)
  80.         {
  81.             un_prev_data=aun_red_buffer[i-1];
  82.             while(INT.read()==1);
  83.             maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i));

  84.             if(aun_red_buffer[i]>un_prev_data)//just to determine the brightness of LED according to the deviation of adjacent two AD data
  85.             {
  86.                 f_temp=aun_red_buffer[i]-un_prev_data;
  87.                 f_temp/=(un_max-un_min);
  88.                 f_temp*=MAX_BRIGHTNESS;
  89.                 n_brightness-=(int)f_temp;
  90.                 if(n_brightness<0)
  91.                     n_brightness=0;
  92.             }
  93.             else
  94.             {
  95.                 f_temp=un_prev_data-aun_red_buffer[i];
  96.                 f_temp/=(un_max-un_min);
  97.                 f_temp*=MAX_BRIGHTNESS;
  98.                 n_brightness+=(int)f_temp;
  99.                 if(n_brightness>MAX_BRIGHTNESS)
  100.                     n_brightness=MAX_BRIGHTNESS;
  101.             }

  102.             pwmled.write(1-(float)n_brightness/256);//pwm control led brightness
  103.                                                 if(n_brightness<120)
  104.                                                         led=1;
  105.                                                 else
  106.                                                         led=0;

  107.             //send samples and calculation result to terminal program through UART
  108.             pc.printf("red=");
  109.             pc.printf("%i", aun_red_buffer[i]);
  110.             pc.printf(", ir=");
  111.             pc.printf("%i", aun_ir_buffer[i]);
  112.             pc.printf(", HR=%i, ", n_heart_rate);
  113.             pc.printf("HRvalid=%i, ", ch_hr_valid);
  114.             pc.printf("SpO2=%i, ", n_sp02);
  115.             pc.printf("SPO2Valid=%i\n\r", ch_spo2_valid);
  116.         }
  117.         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);
  118.     }
  119. }
復制代碼

MAX30102_uvision5_stm32f103c8.7z

557.14 KB, 下載次數: 197, 下載積分: 黑幣 -5

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:924572 發表于 2022-1-20 20:50 | 只看該作者
請問 有max30102 proteus 仿真嗎?
回復

使用道具 舉報

板凳
ID:192215 發表于 2022-5-12 20:11 | 只看該作者
Mr、Zhou 發表于 2022-1-20 20:50
請問 有max30102 proteus 仿真嗎?

MAX30102應該不能仿真吧
回復

使用道具 舉報

地板
ID:1071867 發表于 2023-4-15 12:09 | 只看該作者
kkscan0821 發表于 2022-5-12 20:11
MAX30102應該不能仿真吧

不可以嗎
回復

使用道具 舉報

5#
ID:1072160 發表于 2023-4-18 11:11 | 只看該作者
我想問下樓主,Max30100和這個有什么區別?我不會寫Max30100的驅動
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久国产成人精品国产成人亚洲 | 欧美久久久久久 | 人人干人人超 | 在线视频 亚洲 | 欧美a级成人淫片免费看 | 农村妇女毛片精品久久久 | 欧美福利视频 | 手机看黄av免费网址 | 涩涩视频大全 | 91影视| 国产精品无码久久久久 | 一级片免费视频 | 久久久蜜桃一区二区人 | 99久久中文字幕三级久久日本 | 久久免费精品 | 国产精品久久久久久久久免费软件 | 一区二区三区四区免费在线观看 | 亚洲a视频 | 新av在线| 国产日韩一区二区三区 | 粉嫩一区二区三区性色av | 亚洲欧美在线视频 | 国产伦精品一区二区三毛 | 91视频国产精品 | 精品二区视频 | 国产成人高清成人av片在线看 | 国产精品99久久久久久久久久久久 | 毛片一区二区三区 | www.玖玖玖 | 亚洲精品乱码久久久久久蜜桃91 | 亚洲一二三视频 | 欧美日韩专区 | 日本三级日产三级国产三级 | 日韩免费福利视频 | 亚洲经典一区 | 精品一区二区三区四区外站 | 亚洲精品乱码久久久久久9色 | 欧美一级片在线看 | 国产一区二区三区在线 | 日本一区二区三区免费观看 | 99re视频|