我把程序 贴上了 各位大神帮我看看怎么回事 现在的问题是 dma无法正常发送,我没调用send函数时,led能正常显示 一旦调用了led都无法正确显示 #include "misc.h" #include "stdio.h" #include "math.h" #include "stm32l1xx_adc.h" #include "stm32l1xx_lcd.h" #include "stm32l1xx_rcc.h" #include "stm32l1xx_rtc.h" #include "stm32l1xx_exti.h" #include "stm32l1xx_pwr.h" #include "stm32l1xx_syscfg.h" #include "stm32l1xx_dbgmcu.h" #include "stm32_tsl_api.h" #include "stm32l15x_tsl_ct_acquisition.h" #include "led.h" #include "ClockConfig.h" #include "IIC_Communication.h" #include "afe4400.h" #include "coef_filter.h" #include "Usart.h" #define N 50 #define sample_rate 250 #define Divided_Fre 2 #define High_pass_Orders 667 #define Low_pass_Orders 128 unsigned char Disp_Flag,readDataFlag; int send(void); long AFE44xx_SPO2_Data_buf[6],test,coef_IR[High_pass_Orders],coef_Red[High_pass_Orders],coef_low_IR[Low_pass_Orders],coef_low_Red[Low_pass_Orders]; float XRed[sample_rate],YIRed[sample_rate]; //uint32_t ; //void delay_ms(uint32_t ms); //******main*******// int main(void) { unsigned char i,k,Tmax,x,z,Win_Num,Str_Voltage[9]={0},spo2_value[9]={0}; //unsigned int Fs; unsigned int Freq_Dvider4; int T_data; float Ynt=0.0,Ynt_Red,Fs,Lmax,Lmax_pre,Lmax_bac,Ynt_Disp,XRed_Sum,YIRed_Sum,XRed_Avg,YRed_Avg,R;//XRed[sample_rate],YIRed[sample_rate]; double Lxy,Lxx,Lyy; uint32_t j,T_pre,T_bac=1; uint16_t n; n=0;readDataFlag=0; Freq_Dvider4=1; x=0;k=0;z=0; ClockConfig(); Led_Init(); //³õʼ»¯ÓëLEDÁ¬½ÓµÄÓ²¼þ½Ó¿Ú I2C_Configuration(); OLED_Init(); OLED_CLS();//ÇåÆÁ AFE44xx_PowerOn_Init(); for(i=0;i<5;i++) { OLED_ShowCN_12x12(2+i*12,0,i);//?????? } for(i=5;i<10;i++) { OLED_ShowCN_12x12(2+(i-5)*12,2,i);//?????? } while(1) { if(readDataFlag) { readDataFlag = 0; AFE44xx_SPO2_Data_buf[0] = AFE44xx_Reg_Read(0x2A); //read RED data AFE44xx_SPO2_Data_buf[1] = AFE44xx_Reg_Read(43); //read Ambient data AFE44xx_SPO2_Data_buf[2] = AFE44xx_Reg_Read(44); //read IR Data AFE44xx_SPO2_Data_buf[3] = AFE44xx_Reg_Read(45); //read Ambient Data AFE44xx_SPO2_Data_buf[4] = AFE44xx_Reg_Read(0x2E); //read RED - Ambient Data AFE44xx_SPO2_Data_buf[5] = AFE44xx_Reg_Read(47); //read IR - Ambient Data3 /**************************************high pass filter*****************************************/ coef_IR[0]=AFE44xx_SPO2_Data_buf[5]; coef_Red[0]=AFE44xx_SPO2_Data_buf[4]; for(j=0;j<High_pass_Orders;j++) { Ynt=Ynt+B[j]*coef_IR[j];//IR Ynt_Red=Ynt_Red+B[j]*coef_Red[j];//Red } // AFE44xx_SPO2_Data_buf[5]=Ynt; for(j=0;j<High_pass_Orders-1;j++) { coef_IR[High_pass_Orders-1-j]=coef_IR[High_pass_Orders-1-j-1];//IR High_pass_Orders-1=933-1 coef_Red[High_pass_Orders-1-j]=coef_Red[High_pass_Orders-1-j-1];//Red } // Ynt_Disp=Ynt_Red+3000; //Ynt_Disp=Ynt+200; //Ynt_Disp=AFE44xx_SPO2_Data_buf[5]; Ynt_Disp=Ynt+3000; /**************************************low pass filter*****************************************/ coef_low_IR[0]=(long)Ynt; coef_low_Red[0]=(long)Ynt_Red; for(j=0;j<Low_pass_Orders;j++) { Ynt=Ynt+coef_low_IR[j]*B_low[j];//IR Ynt_Red=Ynt_Red+coef_low_Red[j]*B_low[j]; //Red } for(j=0;j<Low_pass_Orders-1;j++) { coef_low_IR[Low_pass_Orders-1-j]=coef_low_IR[Low_pass_Orders-1-j-1]; coef_low_Red[Low_pass_Orders-1-j]=coef_low_Red[Low_pass_Orders-1-j-1]; } // Ynt=Ynt-3000; // Ynt_Red=Ynt_Red-3000; /**************************************compute Heart rate*****************************************/ if(k<N) { k++; if(Lmax<Ynt){Lmax=Ynt;Tmax=k;}//get the max value } else { Win_Num++; if(Tmax>4&&Tmax<N-4)//¶Ô·åÖµ»®¶¨Çø¼ä { z++; if(z==1) { T_pre=Win_Num*N-N+Tmax;Lmax_pre=Lmax;} else if(z==2) { Lmax_bac=Lmax; T_bac=Win_Num*N-N+Tmax; T_data=T_bac-T_pre; if(T_data>125) { z=0; Win_Num=0; if(fabs(Lmax_pre-Lmax_bac)<150) { Fs=((250.0/(T_bac-T_pre))*60.0); //******************ÏÔʾÐÄÂÊ**************/ Hex_to_dex_to_string((uint16_t)Fs,Str_Voltage,2); OLED_ShowStr(60,2,Str_Voltage,3); //²âÊÔ6*12×Ö·û } } else z=1; } } k=0; Lmax=0; } // //********************************************computer the spo2%***************************************************/ // if(n<sample_rate) { XRed[n]=Ynt; YIRed[n]=Ynt_Red; n++; XRed_Sum+=Ynt; YIRed_Sum+= Ynt_Red; } else { n=0; XRed_Avg=XRed_Sum/sample_rate*1.0; YRed_Avg=YIRed_Sum/sample_rate*1.0; for(j=0;j<sample_rate;j++)// { Lxy=(XRed[j]-XRed_Avg)*(YIRed[j]-YRed_Avg)*1.0+Lxy; Lxx=(XRed[j]-XRed_Avg)*(XRed[j]-XRed_Avg)*1.0+Lxx; Lyy=(YIRed[j]-YRed_Avg)*(YIRed[j]-YRed_Avg)*1.0+Lyy; } R=Lxy/sqrt(Lxx*Lyy)*100.0; send();//我在此处调用 //**************ÏÔʾѪÑõÖµ%************/ Hex_to_dex_to_string((uint16_t)R,spo2_value,5); OLED_ShowStr(60,0,spo2_value,3); Lxy=0.0; Lxx=0.0; Lyy=0.0; XRed_Sum=0; YIRed_Sum=0; } // if(n<sample_rate) // { // XRed[n]=Ynt; // YIRed[n++]=Ynt_Red; // } // else // { // for(j=0;j<sample_rate;j++) // { // XRed_Sum=XRed[j]+XRed_Sum; // YIRed_Sum=YIRed[j]+YIRed_Sum; // } // n=0; // XRed_Avg=XRed_Sum/sample_rate; // YRed_Avg=YIRed_Sum/sample_rate; // for(j=0;j<sample_rate;j++)// // { // Lxy=(XRed[j]-XRed_Avg)*(YIRed[j]-YRed_Avg)+Lxy; // Lxx=(XRed[j]-XRed_Avg)*(XRed[j]-XRed_Avg)+Lxx; // Lyy=(YIRed[j]-YRed_Avg)*(YIRed[j]-YRed_Avg)+Lyy; // } // R=Lxy/sqrt(Lxx*Lyy)*100; // //**************ÏÔʾѪÑõÖµ%************/ // Hex_to_dex_to_string((uint16_t)R,spo2_value,5); // OLED_ShowStr(60,0,spo2_value,3); // XRed_Sum=0; // YIRed_Sum=0; // } //*****************************PPG wave display***************************************************/ if((Freq_Dvider4++)%Divided_Fre==0) { Freq_Dvider4=1; if(Disp_Flag==1){OLED_SetPos_x(x);Disp_Flag=0;} OLED_Disp(x++,Ynt_Disp); if(x==128) { x=0; OLED_CLS_Wave(); } } Ynt_Red=0; Ynt=0; } } } void EXTI0_IRQHandler(void) { if(EXTI_GetITStatus(EXTI_Line0) != RESET) { readDataFlag = 1; test++; if((test)%500==250) GPIO_ResetBits(GPIOB,GPIO_Pin_12); if((test)%500==0) GPIO_SetBits(GPIOB,GPIO_Pin_12); EXTI_ClearITPendingBit(EXTI_Line0); } } //************DMA通信*****************// int send(void) { float SendBuff[2]; //ÉèÖ÷¢ËÍ»º³åÇø float Fs=0.0, R=0.0; RS232_Init(9600); //³õʼ»¯RS232 MYDMA_Config(DMA1_Channel7,(uint32_t)&USART2->DR,(uint32_t)SendBuff,8); DMA_ITConfig(DMA1_Channel7, DMA_IT_TC, ENABLE); AFE44xx_PowerOn_Init(); while(1) { SendBuff[0]=Fs; SendBuff[1]=R; USART_DMACmd(USART2,USART_DMAReq_Tx,ENABLE); MYDMA_Enable(DMA1_Channel7); while(DMA_GetITStatus(DMA1_FLAG_TC7)==RESET) { } DMA_ClearITPendingBit(DMA1_FLAG_TC7); } } |
int send(void)
{
float SendBuff[2]; //ÉèÖ÷¢ËÍ»º³åÇø
float Fs=0.0, R=0.0;
RS232_Init(9600); //³õʼ»¯RS232
MYDMA_Config(DMA1_Channel7,(uint32_t)&USART2->DR,(uint32_t)SendBuff,8);
DMA_ITConfig(DMA1_Channel7, DMA_IT_TC, ENABLE);
AFE44xx_PowerOn_Init();
while(1)
{
..................
}
评分
查看全部评分
2. 很久没有见过这么长的函数了,特别是主函数,建议你将程序分模块吧,看起来更清晰易懂...
评分
查看全部评分
2、为什么要在send()里面初始化RS232_Init(9600)?,是引脚重复使用吗?引脚定义不清楚
3、调试一下,看看PC停在哪里就知道了。
评分
查看全部评分
评分
查看全部评分
评分
查看全部评分
还有 send里面while(1)是什么
评分
查看全部评分
评分
查看全部评分
恩 我发现了 就是这个问题 谢谢
恩 是的 我知道啦