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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

MAX30102空氣質量監測模塊STM32源程序與資料

[復制鏈接]
跳轉到指定樓層
樓主
空氣質量監測模塊芯片數據手冊、電路圖及測試程序

電路原理圖如下:


功能實現:采用STM32F103C8T6小板,驅動血氧心率傳感器max30102,實現PPG信號采集,并將計算的心率和血氧值顯示在0.96寸OLED和串口上。
軟件實現:ST標準庫3.5
硬件連接:
MAX30102:
    VCC<->3.3V
    GND<->GND
    SCL<->PB7
    SDA<->PB8
    IM<->PB9
0.96inch OLED :
    VCC<->3.3V
    GND<->GND
    SCL<->PA5
    SDA<->PA6
    RST<->PA3
    DC<->PA4
    CS<->PA2
USB-TTL:
    5V<->5V
    GND<->GND
    RXD<->PA9
    TXD<->PA10

單片機源程序如下:
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "sys.h"
  4. #include "usart.h"
  5. #include "max30102.h"
  6. #include "myiic.h"
  7. #include "algorithm.h"
  8. #include "oled.h"

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

  17. #define MAX_BRIGHTNESS 255

  18. void dis_DrawCurve(u32* data,u8 x);

  19. int main(void)
  20. {
  21.         //variables to calculate the on-board LED brightness that reflects the heartbeats
  22.         uint32_t un_min, un_max, un_prev_data;  
  23.         int i;
  24.         int32_t n_brightness;
  25.         float f_temp;
  26.         u8 temp_num=0;
  27.         u8 temp[6];
  28.         u8 str[100];
  29.         u8 dis_hr=0,dis_spo2=0;

  30.         NVIC_Configuration();
  31.         delay_init();                     //延時函數初始化         
  32.         uart_init(115200);                 //串口初始化為115200
  33.         LED_Init();
  34.         
  35.         //OLED
  36.         OLED_Init();
  37.         OLED_ShowString(0,0,"  initializing  ",16);
  38.         OLED_Refresh_Gram();//更新顯示到OLED         

  39.         max30102_init();

  40.         printf("\r\n MAX30102  init  \r\n");

  41.         un_min=0x3FFFF;
  42.         un_max=0;
  43.         
  44.         n_ir_buffer_length=500; //buffer length of 100 stores 5 seconds of samples running at 100sps
  45.         //read the first 500 samples, and determine the signal range
  46.     for(i=0;i<n_ir_buffer_length;i++)
  47.     {
  48.         while(MAX30102_INT==1);   //wait until the interrupt pin asserts
  49.         
  50.                 max30102_FIFO_ReadBytes(REG_FIFO_DATA,temp);
  51.                 aun_red_buffer[i] =  (long)((long)((long)temp[0]&0x03)<<16) | (long)temp[1]<<8 | (long)temp[2];    // Combine values to get the actual number
  52.                 aun_ir_buffer[i] = (long)((long)((long)temp[3] & 0x03)<<16) |(long)temp[4]<<8 | (long)temp[5];   // Combine values to get the actual number
  53.             
  54.         if(un_min>aun_red_buffer[i])
  55.             un_min=aun_red_buffer[i];    //update signal min
  56.         if(un_max<aun_red_buffer[i])
  57.             un_max=aun_red_buffer[i];    //update signal max
  58.     }
  59.         un_prev_data=aun_red_buffer[i];
  60.         //calculate heart rate and SpO2 after first 500 samples (first 5 seconds of samples)
  61.     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);
  62.         
  63.         while(1)
  64.         {
  65.                 i=0;
  66.         un_min=0x3FFFF;
  67.         un_max=0;
  68.                
  69.                 //dumping the first 100 sets of samples in the memory and shift the last 400 sets of samples to the top
  70.         for(i=100;i<500;i++)
  71.         {
  72.             aun_red_buffer[i-100]=aun_red_buffer[i];
  73.             aun_ir_buffer[i-100]=aun_ir_buffer[i];
  74.             
  75.             //update the signal min and max
  76.             if(un_min>aun_red_buffer[i])
  77.             un_min=aun_red_buffer[i];
  78.             if(un_max<aun_red_buffer[i])
  79.             un_max=aun_red_buffer[i];
  80.         }
  81.                 //take 100 sets of samples before calculating the heart rate.
  82.         for(i=400;i<500;i++)
  83.         {
  84.             un_prev_data=aun_red_buffer[i-1];
  85.             while(MAX30102_INT==1);
  86.             max30102_FIFO_ReadBytes(REG_FIFO_DATA,temp);
  87.                         aun_red_buffer[i] =  (long)((long)((long)temp[0]&0x03)<<16) | (long)temp[1]<<8 | (long)temp[2];    // Combine values to get the actual number
  88.                         aun_ir_buffer[i] = (long)((long)((long)temp[3] & 0x03)<<16) |(long)temp[4]<<8 | (long)temp[5];   // Combine values to get the actual number
  89.         
  90.             if(aun_red_buffer[i]>un_prev_data)
  91.             {
  92.                 f_temp=aun_red_buffer[i]-un_prev_data;
  93.                 f_temp/=(un_max-un_min);
  94.                 f_temp*=MAX_BRIGHTNESS;
  95.                 n_brightness-=(int)f_temp;
  96.                 if(n_brightness<0)
  97.                     n_brightness=0;
  98.             }
  99.             else
  100.             {
  101.                 f_temp=un_prev_data-aun_red_buffer[i];
  102.                 f_temp/=(un_max-un_min);
  103.                 f_temp*=MAX_BRIGHTNESS;
  104.                 n_brightness+=(int)f_temp;
  105.                 if(n_brightness>MAX_BRIGHTNESS)
  106.                     n_brightness=MAX_BRIGHTNESS;
  107.             }
  108.                         //send samples and calculation result to terminal program through UART
  109.                         if(ch_hr_valid == 1 && n_heart_rate<120)//**/ ch_hr_valid == 1 && ch_spo2_valid ==1 && n_heart_rate<120 && n_sp02<101
  110.                         {
  111.                                 dis_hr = n_heart_rate;
  112.                                 dis_spo2 = n_sp02;
  113.                         }
  114.                         else
  115.                         {
  116.                                 dis_hr = 0;
  117.                                 dis_spo2 = 0;
  118.                         }
  119.                                 printf("HR=%i, ", n_heart_rate);
  120.                                 printf("HRvalid=%i, ", ch_hr_valid);
  121.                                 printf("SpO2=%i, ", n_sp02);
  122.                                 printf("SPO2Valid=%i\r\n", ch_spo2_valid);
  123.                 }
  124.         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);
  125.                
  126.                 //顯示刷新
  127.                 LED0=0;
  128.                 if(dis_hr == 0)  //**dis_hr == 0 && dis_spo2 == 0
  129.                 {
  130.                         sprintf((char *)str,"HR:---        ");//**HR:--- SpO2:---
  131.                 }
  132.                 else{
  133.                         sprintf((char *)str,"HR:%3d        ",dis_hr);//**HR:%3d SpO2:%3d
  134.                 }
  135.                 OLED_ShowString(0,0,str,16);
  136.                 OLED_Fill(0,23,127,63,0);
  137.                 //紅光在上,紅外在下
  138.                 dis_DrawCurve(aun_red_buffer,20);
  139.                 dis_DrawCurve(aun_ir_buffer,0);
  140.                 OLED_Refresh_Gram();//更新顯示到OLED         
  141.         }
  142. }

  143. void dis_DrawCurve(u32* data,u8 x)
  144. {
  145.         u16 i;
  146.         u32 max=0,min=262144;
  147.         u32 temp;
  148.         u32 compress;
  149.         
  150.         for(i=0;i<128*2;i++)
  151.         {
  152.                 if(data[i]>max)
  153. ……………………

  154. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
MAX30102測試資料完整版.7z (1.07 MB, 下載次數: 97)

評分

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

查看全部評分

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

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美视频一区二区三区 | 三级av在线 | 一区二区三区欧美 | 久久国品片| 欧美日韩一区二区三区四区 | 日日射影院 | 精品乱子伦一区二区三区 | 日日摸夜夜爽人人添av | 91在线综合| 欧美一区二区三区在线观看 | 久久精品国产一区 | 91久久精品国产91久久 | 在线成人精品视频 | 99久久99| 免费观看成人性生生活片 | 91亚洲欧美| 成人在线中文字幕 | 7777在线视频免费播放 | 久久成人综合 | 久久看精品 | 国产精品久久久久久久久久免费看 | 雨宫琴音一区二区在线 | 亚洲福利网 | 日本激情一区二区 | 天天夜夜操 | 亚洲精品一区二三区不卡 | 亚洲视频一区在线观看 | 日本精品视频 | 国产精品成av人在线视午夜片 | 九九热这里只有精品在线观看 | 亚洲国产精品人人爽夜夜爽 | 日韩av一区二区在线观看 | 日本超碰| 亚洲综合色站 | 欧美片网站免费 | 亚洲精品在线播放 | 欧美一a一片一级一片 | av网站免费观看 | 涩涩操| 性色av网站| 欧美色综合一区二区三区 |