第一次玩pic32的mcu,MIPS内核
串口通信发送还是比较顺利
但是死活接收不到串口调试助手发送过来的数据
串口重映射比较坑爹,折腾一上午才有点头绪
代码:
/* * File: newmain.c * Author: Liao * * Created on 2014.3.23, 11:39 */ #include <stdio.h> #include <stdlib.h> #include <plib.h> // 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()); 这里就无法进行下一步了
似乎是等待不到接收的数据。请大神帮看看。