ucosii 和lwip成功在mini板上跑了起来,打算用zigbee传输数据到串口2,串口1发送传回的数据到电脑不成功
时间:10-02
整理:3721RD
点击:
ucosii 和lwip成功在mini板上跑了起来,打算用zigbee传输数据到串口2,串口1发送传回的数据到电脑不成功
定义在usmart.h和usmart.c中
#define USART_REC_LEN 200 //?¨ò?×?′ó?óê?×??úêy 200
#define EN_USART1_RX 1 //ê1?ü£¨1£?/???1£¨0£?′??ú1?óê?
extern u8 USART_RX_BUF[USART_REC_LEN]; //?óê??o3?,×?′óUSART_REC_LEN??×??ú.??×??ú?a??DD·?
extern u16 USART_RX_STA; //?óê?×′ì?±ê??
extern u8 USART2_RX_BUF[USART_REC_LEN]; //?óê??o3?,×?′óUSART_REC_LEN??×??ú.??×??ú?a??DD·?
extern u16 USART2_RX_STA; //?óê?×′ì?±ê??
//è?1???′??ú?D???óê?£???2?òa×¢êíò???oê?¨ò?
void uart_init(u32 bound);
void uart2_init(u32 bound);
void uart2_init(u32 bound){
//GPIO???úéè??
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //ê1?üUSART2£?GPIOAê±?ó
//USART1_TX GPIOA.2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA.2
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //?′ó?í?íìê?3?
GPIO_Init(GPIOA, &GPIO_InitStructure);//3?ê??ˉGPIOA.9
//USART1_RX GPIOA.33?ê??ˉ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;//PA3
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//????ê?è?
GPIO_Init(GPIOA, &GPIO_InitStructure);//3?ê??ˉGPIOA.10
//Usart2 NVIC ????
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//?à??ó??è??3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4; //×óó??è??4
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μàê1?ü
NVIC_Init(&NVIC_InitStructure); //?ù?Y???¨μ?2?êy3?ê??ˉVIC??′??÷
//USART 3?ê??ˉéè??
USART_InitStructure.USART_BaudRate = bound;//′??ú2¨ì??ê
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×?3¤?a8??êy?Y??ê?
USART_InitStructure.USART_StopBits = USART_StopBits_1;//ò???í£?1??
USART_InitStructure.USART_Parity = USART_Parity_No;//?T????D£?é??
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//?Tó2?têy?Yá÷????
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //ê?·¢?£ê?
USART_Init(USART2, &USART_InitStructure); //3?ê??ˉ′??ú2
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//?a??′??ú?óêü?D??
USART_Cmd(USART2, ENABLE); //ê1?ü′??21
}
void USART2_IRQHandler(void) //′??ú1?D??·t??3ìDò
{
u8 Res;
#if SYSTEM_SUPPORT_OS //è?1?SYSTEM_SUPPORT_OS?a??£??òDèòa?§3?OS.
OSIntEnter();
#endif
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //?óê??D??(?óê?μ?μ?êy?Y±?D?ê?0x0d 0x0a?á?2)
{
Res =USART_ReceiveData(USART2); //?áè??óê?μ?μ?êy?Y
if((USART2_RX_STA&0x8000)==0)//?óê??′íê3é
{
if(USART2_RX_STA&0x4000)//?óê?μ?á?0x0d
{
if(Res!=0x0a)USART2_RX_STA=0;//?óê?′í?ó,??D??aê?
else USART2_RX_STA|=0x8000; //?óê?íê3éá?
}
else //?1??ê?μ?0X0D
{
if(Res==0x0d)USART2_RX_STA|=0x4000;
else
{
USART2_RX_BUF[USART2_RX_STA&0X3FFF]=Res ;
USART2_RX_STA++;
if(USART2_RX_STA>(USART_REC_LEN-1))USART2_RX_STA=0;//?óê?êy?Y′í?ó,??D??aê??óê?
}
}
}
}
#if SYSTEM_SUPPORT_OS //è?1?SYSTEM_SUPPORT_OS?a??£??òDèòa?§3?OS.
OSIntExit();
#endif
}
主函数
extern extern u8 USART2_RX_BUF[USART_REC_LEN]; //?óê??o3?,×?′óUSART_REC_LEN??×??ú.??×??ú?a??DD·?
int main(void)
{
delay_init(); //?óê±oˉêy3?ê??ˉ
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//éè???D??ó??è??·?×é?a×é2£o2???à??ó??è??£?2???ìó|ó??è??
uart_init(115200); //′??ú3?ê??ˉ?a115200
uart2_init(115200);
LED_Init(); //3?ê??ˉó?LEDá??óμ?ó2?t?ó?ú
KEY_Init(); //3?ê??ˉ°′?ü
LCD_Init(); //3?ê??ˉLCD
usmart_dev.init(72); //3?ê??ˉUSMART
my_mem_init(SRAMIN); //3?ê??ˉ?ú2??ú′?3?
POINT_COLOR=BLUE; //éè??×?ì??aoìé?
LCD_ShowString(30,30,200,16,16,"ENC28J60+STM32");
LCD_ShowString(30,70,200,16,16,"Li Shen Shen Deng");
LCD_ShowString(30,90,200,16,16,"2016/8/16");
POINT_COLOR = BLUE; //à?é?×?ì?
OSInit(); //UCOS3?ê??ˉ
while(lwip_comm_init()) //lwip3?ê??ˉ
{
LCD_ShowString(30,130,200,20,16,"Lwip Init failed!"); //lwip3?ê??ˉ꧰ü
delay_ms(500);
LCD_Fill(30,130,230,150,WHITE);
delay_ms(500);
}
LCD_ShowString(30,130,200,20,16,"Lwip Init Success!"); //lwip3?ê??ˉ3é1|
while(udp_demo_init()) //3?ê??ˉudp_demo(′′?¨udp_demo??3ì)
{
LCD_ShowString(30,150,200,20,16,"UDP failed!"); //udp′′?¨ê§°ü
delay_ms(500);
LCD_Fill(30,150,230,170,WHITE);
delay_ms(500);
}
LCD_ShowString(30,150,200,20,16,"UDP Success!"); //udp′′?¨3é1|
OSTaskCreate(start_task,(void*)0,(OS_STK*)&START_TASK_STK[START_STK_SIZE-1],START_TASK_PRIO);
OSStart(); //?a??UCOS
}
打印任务:
//ledè???
void led_task(void *pdata)
{
while(1)
{
LED0 = !LED0;
printf("%s",USART2_RX_BUF);
OSTimeDlyHMSM(0,0,0,500); //?óê±500ms
}
}
不能打印数据原因是什么?
急求。
仿真调试根本不能进入
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
这个if语句
调试跟踪的UART2的RXNE位直接就是0
只有UART2的CR1的RXNEIE是置位为1
不明白是什么原因
在裸机情况下运行良好可以实现串口2接收数据,串口1转发到电脑的串口调试助手
定义在usmart.h和usmart.c中
#define USART_REC_LEN 200 //?¨ò?×?′ó?óê?×??úêy 200
#define EN_USART1_RX 1 //ê1?ü£¨1£?/???1£¨0£?′??ú1?óê?
extern u8 USART_RX_BUF[USART_REC_LEN]; //?óê??o3?,×?′óUSART_REC_LEN??×??ú.??×??ú?a??DD·?
extern u16 USART_RX_STA; //?óê?×′ì?±ê??
extern u8 USART2_RX_BUF[USART_REC_LEN]; //?óê??o3?,×?′óUSART_REC_LEN??×??ú.??×??ú?a??DD·?
extern u16 USART2_RX_STA; //?óê?×′ì?±ê??
//è?1???′??ú?D???óê?£???2?òa×¢êíò???oê?¨ò?
void uart_init(u32 bound);
void uart2_init(u32 bound);
void uart2_init(u32 bound){
//GPIO???úéè??
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //ê1?üUSART2£?GPIOAê±?ó
//USART1_TX GPIOA.2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA.2
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //?′ó?í?íìê?3?
GPIO_Init(GPIOA, &GPIO_InitStructure);//3?ê??ˉGPIOA.9
//USART1_RX GPIOA.33?ê??ˉ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;//PA3
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//????ê?è?
GPIO_Init(GPIOA, &GPIO_InitStructure);//3?ê??ˉGPIOA.10
//Usart2 NVIC ????
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//?à??ó??è??3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4; //×óó??è??4
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μàê1?ü
NVIC_Init(&NVIC_InitStructure); //?ù?Y???¨μ?2?êy3?ê??ˉVIC??′??÷
//USART 3?ê??ˉéè??
USART_InitStructure.USART_BaudRate = bound;//′??ú2¨ì??ê
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×?3¤?a8??êy?Y??ê?
USART_InitStructure.USART_StopBits = USART_StopBits_1;//ò???í£?1??
USART_InitStructure.USART_Parity = USART_Parity_No;//?T????D£?é??
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//?Tó2?têy?Yá÷????
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //ê?·¢?£ê?
USART_Init(USART2, &USART_InitStructure); //3?ê??ˉ′??ú2
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//?a??′??ú?óêü?D??
USART_Cmd(USART2, ENABLE); //ê1?ü′??21
}
void USART2_IRQHandler(void) //′??ú1?D??·t??3ìDò
{
u8 Res;
#if SYSTEM_SUPPORT_OS //è?1?SYSTEM_SUPPORT_OS?a??£??òDèòa?§3?OS.
OSIntEnter();
#endif
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //?óê??D??(?óê?μ?μ?êy?Y±?D?ê?0x0d 0x0a?á?2)
{
Res =USART_ReceiveData(USART2); //?áè??óê?μ?μ?êy?Y
if((USART2_RX_STA&0x8000)==0)//?óê??′íê3é
{
if(USART2_RX_STA&0x4000)//?óê?μ?á?0x0d
{
if(Res!=0x0a)USART2_RX_STA=0;//?óê?′í?ó,??D??aê?
else USART2_RX_STA|=0x8000; //?óê?íê3éá?
}
else //?1??ê?μ?0X0D
{
if(Res==0x0d)USART2_RX_STA|=0x4000;
else
{
USART2_RX_BUF[USART2_RX_STA&0X3FFF]=Res ;
USART2_RX_STA++;
if(USART2_RX_STA>(USART_REC_LEN-1))USART2_RX_STA=0;//?óê?êy?Y′í?ó,??D??aê??óê?
}
}
}
}
#if SYSTEM_SUPPORT_OS //è?1?SYSTEM_SUPPORT_OS?a??£??òDèòa?§3?OS.
OSIntExit();
#endif
}
主函数
extern extern u8 USART2_RX_BUF[USART_REC_LEN]; //?óê??o3?,×?′óUSART_REC_LEN??×??ú.??×??ú?a??DD·?
int main(void)
{
delay_init(); //?óê±oˉêy3?ê??ˉ
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//éè???D??ó??è??·?×é?a×é2£o2???à??ó??è??£?2???ìó|ó??è??
uart_init(115200); //′??ú3?ê??ˉ?a115200
uart2_init(115200);
LED_Init(); //3?ê??ˉó?LEDá??óμ?ó2?t?ó?ú
KEY_Init(); //3?ê??ˉ°′?ü
LCD_Init(); //3?ê??ˉLCD
usmart_dev.init(72); //3?ê??ˉUSMART
my_mem_init(SRAMIN); //3?ê??ˉ?ú2??ú′?3?
POINT_COLOR=BLUE; //éè??×?ì??aoìé?
LCD_ShowString(30,30,200,16,16,"ENC28J60+STM32");
LCD_ShowString(30,70,200,16,16,"Li Shen Shen Deng");
LCD_ShowString(30,90,200,16,16,"2016/8/16");
POINT_COLOR = BLUE; //à?é?×?ì?
OSInit(); //UCOS3?ê??ˉ
while(lwip_comm_init()) //lwip3?ê??ˉ
{
LCD_ShowString(30,130,200,20,16,"Lwip Init failed!"); //lwip3?ê??ˉ꧰ü
delay_ms(500);
LCD_Fill(30,130,230,150,WHITE);
delay_ms(500);
}
LCD_ShowString(30,130,200,20,16,"Lwip Init Success!"); //lwip3?ê??ˉ3é1|
while(udp_demo_init()) //3?ê??ˉudp_demo(′′?¨udp_demo??3ì)
{
LCD_ShowString(30,150,200,20,16,"UDP failed!"); //udp′′?¨ê§°ü
delay_ms(500);
LCD_Fill(30,150,230,170,WHITE);
delay_ms(500);
}
LCD_ShowString(30,150,200,20,16,"UDP Success!"); //udp′′?¨3é1|
OSTaskCreate(start_task,(void*)0,(OS_STK*)&START_TASK_STK[START_STK_SIZE-1],START_TASK_PRIO);
OSStart(); //?a??UCOS
}
打印任务:
//ledè???
void led_task(void *pdata)
{
while(1)
{
LED0 = !LED0;
printf("%s",USART2_RX_BUF);
OSTimeDlyHMSM(0,0,0,500); //?óê±500ms
}
}
不能打印数据原因是什么?
急求。
仿真调试根本不能进入
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
这个if语句
调试跟踪的UART2的RXNE位直接就是0
只有UART2的CR1的RXNEIE是置位为1
不明白是什么原因
在裸机情况下运行良好可以实现串口2接收数据,串口1转发到电脑的串口调试助手
已退回1积分