RN42-XV Bluetooth モジュールを使用して、コンピュータから 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;
}
問題は、プログラムが関数 waitForChar() 内で while ループに入らないことです。これは、UART 割り込みフラグがハードウェアによって決して上げられないためです。さまざまな PIC24F を試しましたが、すべて同じ問題が発生します。