这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界» 论坛首页» 企业专区» Microchip» pic32串口通信问题

共6条 1/1 1 跳转至

pic32串口通信问题

高工
2014-03-24 14:38:30 打赏

第一次玩pic32的mcu,MIPS内核

串口通信发送还是比较顺利

但是死活接收不到串口调试助手发送过来的数据

串口重映射比较坑爹,折腾一上午才有点头绪

代码:

/* * File: newmain.c * Author: Liao * * Created on 2014.3.23, 11:39 */ #include  #include  #include  // Configuration Bit settings // SYSCLK = 40 MHz (8MHz Crystal/ FPLLIDIV * FPLLMUL / FPLLODIV) // PBCLK = 40 MHz // Primary Osc w/PLL (XT+,HS+,EC+PLL) // WDT OFF // Other options are don't care // #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF #pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1 #define SYS_FREQ (40000000L) #define DESIRED_BAUDRATE (9600) // The desired BaudRate int main(void) { int pbClk; unsigned char data; RPB3R = 1;//U1TX---RPB3 caution // U1RXR = 0;//U1RX---RPA2 // Configure the device for maximum performance but do not change the PBDIV // Given the options, this function will change the flash wait states, RAM // wait state and enable prefetch cache but will not change the PBDIV. // The PBDIV value is already set via the pragma FPBDIV option above.. pbClk=SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); // Open UART2 with Receive and Transmitter enable. OpenUART1(UART_EN, UART_RX_ENABLE | UART_TX_ENABLE, pbClk/16/DESIRED_BAUDRATE/5-1); // calculate actual BAUD generate value. mPORTASetPinsDigitalOut(BIT_0); // Make RPA0 as output. mPORTASetBits(BIT_0); // Set RPA0. putsUART1("*** UART Simple Application Example ***\r\n"); putsUART1("*** Type some characters and observe echo and RA7 LED toggle ***\r\n"); while(1) { while(!DataRdyUART1()); /* Wait for data in the UARTRx. */ data = (char)ReadUART1(); /* Read data from Rx. */ while(BusyUART1()); /* Wait till the UART transmitter is free. */ putcUART1(data); /* Write data into Tx. */ }; return 0; }

程序执行到

while(!DataRdyUART1()); 这里就无法进行下一步了
似乎是等待不到接收的数据。

请大神帮看看。


高工
2014-03-24 14:47:13 打赏
2楼
应该放在中断里处理串口的数据比较好

高工
2014-03-24 14:50:32 打赏
3楼

有没有开接收中断?



高工
2014-03-24 15:04:38 打赏
4楼
没用中断,查的

高工
2014-03-24 15:05:03 打赏
5楼
直接在查......

高工
2014-03-24 22:18:38 打赏
6楼
我之前遇到过同样的问题,倒腾了一上午

共6条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]