初级会员
- 积分
- 62
- 金钱
- 62
- 注册时间
- 2017-7-2
- 在线时间
- 12 小时
|
5金钱
我已经把C++的宏定义修改成了STM32F10X_MD,USE_STDPERIPH_DRIVER
以下是主程序
#include "stm32f10x.h"
#include "stdio.h"
#include "pwm.h"
#include "usart.h"
#include "delay.h"
unsigned char ucStra[6],ucStrw[6],ucStrAngle[6];
float Value[9];
unsigned char Re_buf[11],counter=0;
void USART2_IRQHandler(void) //串口2中断服务程序,解析mpu6050串口输出数据
{
if(USART_GetITStatus(USART2,USART_IT_RXNE))
{
Re_buf[counter]=USART_ReceiveData(USART2);
// USART_SendData(USART1,Re_buf[counter]);
if(counter==0&&Re_buf[0]!=0x55) return; //第0号数据不是帧头
counter++;
if(counter==11) //接收到11个数据
{
counter=0; //重新赋值,准备下一帧数据的接收
switch(Re_buf [1])
{
case 0x51:
ucStra[0]=Re_buf[2];
ucStra[1]=Re_buf[3];
ucStra[2]=Re_buf[4];
ucStra[3]=Re_buf[5];
ucStra[4]=Re_buf[6];
ucStra[5]=Re_buf[7];
break;
case 0x52:
ucStrw[0]=Re_buf[2];
ucStrw[1]=Re_buf[3];
ucStrw[2]=Re_buf[4];
ucStrw[3]=Re_buf[5];
ucStrw[4]=Re_buf[6];
ucStrw[5]=Re_buf[7];
break;
case 0x53:
ucStrAngle[0]=Re_buf[2];
ucStrAngle[1]=Re_buf[3];
ucStrAngle[2]=Re_buf[4];
ucStrAngle[3]=Re_buf[5];
ucStrAngle[4]=Re_buf[6];
ucStrAngle[5]=Re_buf[7];
break;
}
}
}
}
int fputc(int ch,FILE *f) //调用stdio文件中fputc函数,方便串口使用printf打印输出
{
USART_SendData(USART1,(u8)ch);
while(!(USART1->SR&USART_FLAG_TXE));
return(ch);
}
void UART1_Send_Str(float *s) //串口1输出字符串
{
unsigned char i=0;
while(s[i]!='\0')
{
USART_SendData(USART1,s[i]);
while( USART_GetFlagStatus(USART1,USART_FLAG_TC)!= SET);
i++;
}
}
int main()
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// 设置中断优先级分组2
USART1_init(9600); //串口初始化为9600
USART2_Config();
TIM2_Init(2999,0);
TIM4_Init(49,7199);
while(1)
{
// USART_SendData(USART1,ucStra[1]);
// Value[0] = ((short)(ucStra[1]<<8| ucStra[0]))/32768.0*16;
// Value[1] = ((short)(ucStra[3]<<8| ucStra[2]))/32768.0*16;
// Value[2] = ((short)(ucStra[5]<<8| ucStra[4]))/32768.0*16;
// printf("a:%.3f %.3f %.3f ",Value[0],Value[1],Value[2]);
// Value[3] = ((short)(ucStrw[1]<<8| ucStrw[0]))/32768.0*2000;
//Value[4] = ((short)(ucStrw[3]<<8| ucStrw[2]))/32768.0*2000;
// Value[5] = ((short)(ucStrw[5]<<8| ucStrw[4]))/32768.0*2000;
printf("w:%.3f %.3f %.3f ",Value[3],Value[4],Value[5]);
//Value[6] = ((short)(ucStrAngle[1]<<8| ucStrAngle[0]))/32768.0*180;
//Value[7] = ((short)(ucStrAngle[3]<<8| ucStrAngle[2]))/32768.0*180;
//Value[8] = ((short)(ucStrAngle[5]<<8| ucStrAngle[4]))/32768.0*180;
//printf("A:%.2f %.2f %.2f\r\n",Value[6],Value[7],Value[8]);
}
}
串口助手啥的不显示
|
|