我正在使用RN42-XV藍牙模塊從計算機向PIC24F發送字符。 模塊正確連接/配對,發送的字符也正確(用示波器)。UART緩衝區未在PIC24F上產生標誌
這是它是如何被初始化:
void initUART(){
//Peripheral Pin Mapping
RPINR19bits.U2RXR = 5; //pin 14 UART Receive
RPOR5bits.RP11R = 3; //pin 17 UART Transmit
//Configuring the UART
U2BRG = BRGVAL;
U2MODEbits.UARTEN = 1;
U2MODEbits.UEN = 0;
U2MODEbits.PDSEL = 0;// 8 bit no parity
U2MODEbits.STSEL = 0; // 1 stop bit
U2STAbits.UTXEN = 0;
U2STAbits.URXISEL = 0;
//Putting the UART interrupt flag down.
IFS1bits.U2RXIF = 0;
}
我也是用這個函數來獲得緩衝區的內容:
int waitForChar(){
int receivedChar;
// Use the UART RX interrupt flag to wait until we recieve a character.
while(IFS1bits.U2RXIF == 1){
// Clear the UART RX interrupt flag to we can detect the reception
// of another character.
IFS1bits.U2RXIF = 0;
// U2RXREG stores the last character received by the UART. Read this
// value into a local variable before processing.
receivedChar = U2RXREG;
}
return receivedChar;
}
的問題是,該計劃從未進入while函數在waitForChar()函數內循環,因爲UART中斷標誌永遠不會被硬件產生。 我已經嘗試過不同的PIC24F,但都遇到同樣的問題。
是的,這被改爲返回int。這並沒有幫助緩衝區讀取任何內容。 –