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

標題: stm32c8t6+max30102心率傳感器+0.96 oled顯示源碼 [打印本頁]

作者: ali18082327029    時間: 2018-10-30 21:01
標題: stm32c8t6+max30102心率傳感器+0.96 oled顯示源碼
max30102心率傳感制作。
功能實現:采用STM32F103C8T6小板(bluepill板),驅動血氧心率傳感器HXDZ-30102或HXDZ-30102-ACC(MAX30102),實現PPG信號采集,并將計算的心率和血氧值顯示在0.96寸OLED和串口上。
軟件實現:ST標準庫3.5
硬件連接:
HXDZ-30102:
    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 && 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_spo2 == 0)
  129.                 {
  130.                         sprintf((char *)str,"HR:--- SpO2:--- ");
  131.                 }
  132.                 else{
  133.                         sprintf((char *)str,"HR:%3d SpO2:%3d ",dis_hr,dis_spo2);
  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.                         max = data[i];
  155.                 }
  156.                 if(data[i]<min)
  157.                 {
  158.                         min = data[i];
  159.                 }
  160.         }
  161.        
  162.         compress = (max-min)/20;
  163.        
  164.         for(i=0;i<128;i++)
  165.         {
  166.                 temp = data[i*2] + data[i*2+1];
  167.                 temp/=2;
  168.                 temp -= min;
  169.                 temp/=compress;
  170.                 if(temp>20)temp=20;
  171.                 OLED_DrawPoint(i,63-x-temp,1);
  172.         }
  173. }
復制代碼

所有資料51hei提供下載:
MAX30102.rar (320.96 KB, 下載次數: 674)



作者: 上善若水123456    時間: 2018-10-31 09:17
學習一下
作者: 秋名山老司機666    時間: 2018-11-1 14:51
有實物圖嗎?
作者: Ivy_Lee    時間: 2018-11-2 17:51
找到的30102官方測試程序,共享一下

max30102測試程序.rar

5.48 MB, 下載次數: 200, 下載積分: 黑幣 -5


作者: 534766695    時間: 2018-12-20 20:53
這個的采樣率是多少
作者: Barry26    時間: 2019-3-15 10:44
學習一下
作者: 自由電子    時間: 2019-5-27 22:12
謝謝分享,學習一下!
作者: 努力拿獎    時間: 2019-6-10 19:27
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);
69行的這個函數在哪里

作者: jnq123    時間: 2020-2-21 14:24
有圖片就好了。。。
作者: dtthj    時間: 2020-3-15 18:53
可以改用52嗎

作者: ybjklabbbubunu    時間: 2020-4-10 08:08
請教大神,max30100和stm32f103c8t6怎么接線

作者: liuhongyudy    時間: 2020-5-13 15:31
這個n_brightness變量一通算,最后還是沒用上啊,這個應該是要用于反饋調整led亮度的。
作者: zenglei    時間: 2021-4-28 22:28
有實物圖嗎?
作者: lv1    時間: 2021-8-6 09:52
樓主用的是什么MAX30102芯片?我下載了只有心率值,血氧為-999是怎么回事

作者: zyluglugl    時間: 2021-8-6 19:18
樓主這個做成成品了嗎?低功耗做得怎么樣?
作者: richardgann    時間: 2023-10-18 13:39
感謝提供思路  非常感謝
作者: cherry0808    時間: 2023-11-16 21:54
能做出實物嗎
作者: @gaoqian    時間: 2023-12-12 19:56
我覺得挺不錯的,有注釋,不會太費勁
作者: 274904367    時間: 2024-1-24 18:11
Ivy_Lee 發表于 2018-11-2 17:51
找到的30102官方測試程序,共享一下

謝謝分享 參與一下




歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 91视视频在线观看入口直接观看 | 特黄级国产片 | 亚洲h视频 | 精品99在线 | 最新av在线网址 | 亚洲免费高清 | 国内精品久久影院 | 国产精品欧美一区喷水 | 国产精品1区2区3区 欧美 中文字幕 | 91在线看| 成人日b视频 | 精品毛片在线观看 | 欧美综合一区 | 日韩av成人在线 | 欧美日韩一区二区电影 | 亚洲人免费视频 | 国产激情一区二区三区 | 国产一区二区三区视频在线观看 | 国产精品国产三级国产aⅴ原创 | 中文字幕精品视频 | 国产欧美精品一区二区色综合朱莉 | 91精品欧美久久久久久久 | 97精品久久 | 亚洲成人免费观看 | 久久青青| 日本免费一区二区三区四区 | 国产视频一区在线 | 国产精品久久久久久影院8一贰佰 | 日本韩国电影免费观看 | 91 在线| 一区二区三区在线 | 亚洲精品视频在线看 | 午夜精品一区二区三区免费视频 | 日韩高清中文字幕 | 在线观看国产视频 | 久草网站 | 色偷偷888欧美精品久久久 | 第一区在线观看免费国语入口 | 精品美女视频在免费观看 | 久久美女网 | 在线一区视频 |