void USART2_IRQHandler(void)
{
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
Re_buf[counter]=USART_ReceiveData(USART2);
USART_ClearFlag(USART2, USART_FLAG_TC);
if(counter==0&& Re_buf[0]!=0x55) return;
counter++;
if(counter==11)
{
counter=0;
sign=1;
}
}
}
主函数里边对sign的值进行判断,判断后将其置0,但是中断函数只能执行2次,就再也不对sign置1了。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
{
D1=1;
D2=1;
D3=1;
D4=1;
p=1;
d=1;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//éèÖÃÏμí3ÖD¶ÏóÅÏ輶·Ö×é2
uart_init(9600);//′®¿ú3õê¼»ˉ2¨ìØÂêÎa9600
uart2_init(9600);//óÃóú½óêÕà′×ÔMPU6050μÄêy¾Y
delay_init(168);//Ñóê±3õê¼»ˉ
LED_Init();
GPIO_4_init();
TIM3_PWM_Init(500-1,84-1); //84M/84=1MhzμļÆêyÆμÂê,ÖØ×°ÔØÖμ500£¬ËùòÔWMÆμÂêÎa 1M/500=2Khz.
delay_ms(200);
while(1)
{
LED0 =0;//0μÆáá
if(sign)
{
memcpy(Temp,Re_buf,11);// memcpyÄú′濽±′oˉêyÔústring.hÖD,×÷óÃêÇ′óRe_bufÖD¸′ÖÆ11¸öêyμ½tempÖD
sign=0;
if(Re_buf[0]==0x55) //¼ì2éÖ¡í·
{
switch(Re_buf[1])
{
case 0x51: //±êê¶Õa¸ö°üêǼóËù¶è°ü
a[0] = ((short)(Temp[3]<<8 | Temp[2]))/32768.0*16; //XÖá¼óËù¶èshortè¡Öμ·¶Î§-32768¡¤32767
a[1] = ((short)(Temp[5]<<8 | Temp[4]))/32768.0*16; //YÖá¼óËù¶è
a[2] = ((short)(Temp[7]<<8 | Temp[6]))/32768.0*16; //ZÖá¼óËù¶è
T = ((short)(Temp[9]<<8 | Temp[8]))/340.0+36.25; //릏
break;
case 0x52: //±êê¶Õa¸ö°üêǽÇËù¶è°ü
w[0] = ((short)(Temp[3]<<8| Temp[2]))/32768.0*2000; //XÖá½ÇËù¶è
w[1] = ((short)(Temp[5]<<8| Temp[4]))/32768.0*2000; //YÖá½ÇËù¶è
w[2] = ((short)(Temp[7]<<8| Temp[6]))/32768.0*2000; //ZÖá½ÇËù¶è
T = ((short)(Temp[9]<<8| Temp[8]))/340.0+36.25; //릏
break;
case 0x53: //±êê¶Õa¸ö°üêǽǶè°ü
angle[0] = ((short)(Temp[3]<<8| Temp[2]))/32768.0*180; //XÖá1ö×a½Ç£¨x Öᣩ
angle[1] = ((short)(Temp[5]<<8| Temp[4]))/32768.0*180; //YÖḩÑö½Ç£¨y Öᣩ
angle[2] = ((short)(Temp[7]<<8| Temp[6]))/32768.0*180; //ZÖáÆ«o½½Ç£¨z Öᣩ
T = ((short)(Temp[9]<<8| Temp[8]))/340.0+36.25; //릏
break;
default: break;
}
// USART_SendData(USART1,angle[0]); //óÃ′®¿ú1·¢Ëíò»¸ö×Ö½ú
// while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); //μè′y′®¿ú1·¢Ëííê±Ï
if( angle[0]>0)//angle[0]:XÖá1ö×a½Ç£¨x Öᣩ, w[0]:XÖá½ÇËù¶è
TIM_SetCompare1(TIM3,2);//PA6DT¸Ä±è½ÏÖ죬DT¸ÄÕ¼¿Õ±è ,Öμ2»Äü3¬1yÖüÆú£o500
else
TIM_SetCompare2(TIM3,10);
}
}
这是主函数
一周热门 更多>