//串口1中断服务程序
//注意,读取USARTx->SR能避免莫名其妙的错误
u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.
//接收状态
//bit15, 接收完成标志
//bit14, 接收到0x0d
//bit13~0, 接收到的有效字节数目
u16 USART_RX_STA=0; //接收状态标记
void USART1_IRQHandler(void) //串口1中断服务程序
{
u8 Res;
#ifdef OS_TICKS_PER_SEC //如果时钟节拍数定义了,说明要使用ucosII了.
OSIntEnter();
#endif
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾)
{
Res =USART_ReceiveData(USART1);//(USART1->DR); //读取接收到的数据
if((USART_RX_STA&0x8000)==0)//1000 0000 0000 0000接收未完成
{
if(USART_RX_STA&0x4000)//100 0000 0000 0000接收到了0x0d
{
if(Res!=0x0a)USART_RX_STA=0;//接收错误,重新开始
else USART_RX_STA|=0x8000; //接收完成了
}
else //还没收到0X0D
{
if(Res==0x0d)USART_RX_STA|=0x4000;
else
{
USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ;
USART_RX_STA++;
if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//接收数据错误,重新开始接收
}
}
}
}
int main(void)
{
u32 i,j;
// u8 size=3; //默认是QVGA 320*240尺寸
// u32 jpeglen=0;
//u32 bag=0;//包数
uart_init(115200);//115200); //初始化串口波特率为115200
delay_init(168); //初始化延时函数
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
LCD_Init(); //液晶屏初始
LED_Init();
LED1=1;
LED2=1;
main_test(); //测试主界面
printf("AT+RST
");//串口1发送命令
USART_RX_STA=0; //清除串口1标志位
while(USART_RX_STA&=0x8000);//等待串口1接收完数据
LCD_ShowString(10,16,16,"AT+RST",1);//示显字符串AT+RST
LCD_ShowString(10+48,16,16,USART_RX_BUF,1);//示显串中1接收的数据
LED1=0;//点亮
LED2=0;
}
上面代码很奇怪,串口没收到任何数据,屏上就示显字符串AT+RST,LED也点亮了
按道理,串口收到0x0d,0x0a,才会在屏上示显字符串AT+RST,然后才点亮LED啊!
大家帮帮我看那里出了问题?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
回复【2楼】正点原子:
---------------------------------
有的啊,我只是写了一部分,看起来简单好懂点,
u8 strCmp(u8 *s1,u8 *s2){
u8 i;
for(i=0;s2!=0;i++){// s1!=0||
if(s1<s2)return 2;
else if(s1>s2)return 1;
}
return 0;
}
int main(void)
{
u32 i,j;
// u8 size=3; //??????QVGA 320*240????
// u32 jpeglen=0;
//u32 bag=0;//°ü??
uart_init(115200);//115200); //???????????¨??????115200
delay_init(168); //?????????±????
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//?è????????????????·?×é2
LCD_Init(); //???§??????
LED_Init();
//MYDMA_Config(DMA2_Stream7,DMA_Channel_4,(u32)&USART1->DR,(u32)JpegBuffer,JpegDataCnt);//DMA2,STEAM7,CH4,???è??????1,?????÷??SendBuff,?¤????:SEND_BUF_SIZE.
OV2640_Init();
OV2640_JPEG_Mode(); //JPEG????
OV2640_OutSize_Set(800,600);//(jpeg_img_size_tbl[size][0],jpeg_img_size_tbl[size][1]);//?è??????????
SCCB_WR_Reg(0XFF,0X00);
SCCB_WR_Reg(0XD3,30);
SCCB_WR_Reg(0XFF,0X01);
SCCB_WR_Reg(0X11,0X1);
EXTI->IMR &= ~EXTI_Line0; //??±???????????
EXTI->EMR &= ~EXTI_Line0;
EXTI->IMR &= ~EXTI_Line2; //??±?????????????
EXTI->EMR &= ~EXTI_Line2;
// delay_us(100);
//Delay_nMS(10); //???????????????¨
delay_ms(10);
EXTI->IMR |= EXTI_Line0; //????????????????×?±?????????
EXTI->EMR |= EXTI_Line0;
//printf("AT+CWMODE=1 ");
main_test(); //?????÷????
//delay_ms(1000);
printf("AT+RST ");
USART_RX_STA=0;
while(USART_RX_STA&=0x8000);
//delay_ms(10000);
LCD_ShowString(10,16,16,"AT+RST",1);
LCD_ShowString(10+48,16,16,USART_RX_BUF,1);
printf("AT+CWMODE=1 ");
USART_RX_STA=0;
while(USART_RX_STA&=0x8000);
//delay_ms(10000);
LCD_ShowString(10,32,16,"AT+CWMODE=1",1);
LCD_ShowString(10+88,32,16,USART_RX_BUF,1);
//USART_RX_STA=0;
printf("AT+CWLAP ");//?¨?è??WIFI ok
USART_RX_STA=0;
while(USART_RX_STA&=0x8000);
//delay_ms(10000);
LCD_ShowString(10,48,16,"AT+CWLAP",1);
LCD_ShowString(10+64,48,16,USART_RX_BUF,1);
//USART_RX_STA=0;
printf("AT+CWJAP="www.13aiyt.com","81314477" ");//????wifi
USART_RX_STA=0;
while(USART_RX_STA&=0x8000);
//delay_ms(10000);
LCD_ShowString(10,64,16,"AT+CWJAP=",1);
LCD_ShowString(10+72,64,16,USART_RX_BUF,1);
// USART_RX_STA=0;
printf("AT+CIPMUX=1 ");//?à?¨???¨??????
USART_RX_STA=0;
while(USART_RX_STA&=0x8000);
//delay_ms(10000);
LCD_ShowString(10,80,16,"AT+CIPMUX=1",1);
LCD_ShowString(10+88,80,16,USART_RX_BUF,1);
printf("AT+CIPSERVER=1,5000 ");//??????·????÷??5000?????à??
LED1=0;
LED2=0;
USART_RX_STA=0;
while(USART_RX_STA&=0x8000);
while(strCmp(USART_RX_BUF,"Link")==0);
LCD_ShowString(10,96,16,USART_RX_BUF,1);
LED1=0;
LED2=1;
//delay_ms(10000);
LCD_ShowString(10,112,16,"Flash Disk Format Error ",1); //???????§°?
while(1)
{// LCD_ShowString(10,72,16,"Flash Disk Format Error ",1); //???????§°?
if(VsyncActive == 2)
{
for(i = 0; i < JpegDataCnt; i ++)
{
if(JpegDataCnt>1024)
{
printf("AT+CIPSEND=0,1024 ");
delay_ms(10);
while(0==strCmp(USART_RX_BUF,ned));
delay_ms(10000);
for(j = 0; j < 1024; j ++)
{
USART_SendData(USART1,JpegBuffer[i+j]);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
}
i=i+1024;
}else
{
printf("AT+CIPSEND=0,%d ",JpegDataCnt);
delay_ms(10);
//while(0=strcmp(USART_RX_BUF,?°> ?±));
while(0==strCmp(USART_RX_BUF,ned));
for(j = 0; j < JpegDataCnt; j ++)
{
USART_SendData(USART1,JpegBuffer[j]);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
}
i=i+j;
}
}
JpegDataCnt = 0; //JPEG?????÷????
VsyncActive =0;
EXTI->IMR |= EXTI_Line0; //????????????????×?±?????????
EXTI->EMR |= EXTI_Line0;
}
}
一周热门 更多>