|
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "string.h"
#include "max30102.h"
#include <stdio.h>
#define MAX_BRIGHTNESS 255
#define INTERRUPT_REG 0X00
/* VCC<->3.3V
GND<->GND
SCL<->PB7
SDA<->PB8
INT<->PB9*/
uint32_t aun_ir_buffer[500];
int32_t n_ir_buffer_length;
uint32_t aun_red_buffer[500];
int32_t n_sp02;
int8_t ch_spo2_valid;
int32_t n_heart_rate;
int8_t ch_hr_valid;
uint8_t Temp;
uint32_t un_min;
uint32_t un_max;
uint32_t un_prev_data;
int i;
int32_t n_brightness;
float f_temp;
u8 temp[6];
u8 str[100];
u8 dis_hr=0,dis_spo2=0;
#define HR_ADDR 0x3000
#define SPO2_ADDR 0x3200
#define DGUS_HEADER1 0x5A
#define DGUS_HEADER2 0xA5
#define CALC_DATA_LENGTH(data) (sizeof(data) / sizeof(data[0]))
int main(void)
{
delay_init(72);
LED_Init();
USART2_Config();
MAX30102_Init();
un_min = 0x3FFFF;
un_max = 0;
n_ir_buffer_length = 500;
for(i = 0; i < n_ir_buffer_length; i++)
{
while(MAX30102_INT == 1);
max30102_FIFO_ReadBytes(REG_FIFO_DATA, temp);
aun_red_buffer = (long)((long)((long)temp[0]&0x03)<<16) | (long)temp[1]<<8 | (long)temp[2];
aun_ir_buffer = (long)((long)((long)temp[3] & 0x03)<<16) |(long)temp[4]<<8 | (long)temp[5];
if(un_min > aun_red_buffer)
un_min = aun_red_buffer;
if(un_max < aun_red_buffer)
un_max = aun_red_buffer;
}
un_prev_data = aun_red_buffer;
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);
while(1)
{
for(i = 100; i < 500; i++)
{
aun_red_buffer[i - 100] = aun_red_buffer;
aun_ir_buffer[i - 100] = aun_ir_buffer;
if(un_min > aun_red_buffer)
un_min = aun_red_buffer;
if(un_max < aun_red_buffer)
un_max = aun_red_buffer;
}
for(i = 400; i < 500; i++)
{
un_prev_data = aun_red_buffer[i - 1];
while(MAX30102_INT == 1);
max30102_FIFO_ReadBytes(REG_FIFO_DATA, temp);
aun_red_buffer = (long)((long)((long)temp[0]&0x03)<<16) | (long)temp[1]<<8 | (long)temp[2];
aun_ir_buffer = (long)((long)((long)temp[3] & 0x03)<<16) |(long)temp[4]<<8 | (long)temp[5];
if(aun_red_buffer > un_prev_data)
{
f_temp = aun_red_buffer - 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;
f_temp /= (un_max - un_min);
f_temp *= MAX_BRIGHTNESS; // ??(????)=(??? - ???)/(??? - ???)*255
n_brightness += (int)f_temp;
if(n_brightness > MAX_BRIGHTNESS)
n_brightness = MAX_BRIGHTNESS;
}
}
// ?? UART ???????????????
if(ch_hr_valid == 1 && n_heart_rate < 120)
{
dis_hr = n_heart_rate;
dis_spo2 = n_sp02;
}
else
{
dis_hr = 0;
dis_spo2 = 0;
}
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);
SendDataToDGUS(HR_ADDR, dis_hr);
SendDataToDGUS(SPO2_ADDR, dis_spo2);
}
}
这个是主函数,我想问下哪里有问题,我传输不到数据给迪文屏
|
|