新手入门
- 积分
- 5
- 金钱
- 5
- 注册时间
- 2016-8-19
- 在线时间
- 0 小时
|
6金钱
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转发到电脑的串口调试助手
|
|