您好,我正在尝试使用PIC24EP64 GP202 UART1来读取使用RX中断。它似乎只读一次,以后再也不会读了。这几乎就像中断标志不清楚。我希望接收的消息在7到135字节之间。所以我基本上只想把UART刷新成一个循环缓冲器。有人能帮我弄清楚到底发生了什么吗?BoOL8YT UARTHI初始化(空隙){IEC0= 0xMUN;//禁用IEC1= 0xMUN;IEC3= 0xMUN;IEC4=0xFUN;LATA= 0xFFFF;//所有HI LATB= 0xF7FF;//所有HI除外RS48 5TXEN TrISA=0xFFFF;//TrISB= 0xB0FF;//除SCL、SDA、RS48 5TX、RS48 5TXEN、Tokoo ANSELLA=0x000以外的所有输入0;//所有ANX输入设置为数字I/O//UART1 PLEF PIN选择(PPS)RPNR18BITS。U1RXR=44;/ /分配U1RX到RPI44(RB12)三比特。
tiSBB12=1;//作为输入RPOR4BITS。RP42R=1;/ /分配U1TX到RP42(RB10)三比特。TISISB10=0;/ /作为输出U1MODE=0XA800;//设置UART1:启用UART1;停止在空闲模式//U1MODE=0xA808;;……高速/ //RX启用,RTS *单工模式/:没有唤醒,回退禁用,波特率测量禁用,RX空闲HI,//:丢失模式,8位,1停止位U1BRG=7;//5:6K波特U1STA= 0X0400;//TX启用,中断禁用,ADDR检测禁用U2禁用模式UART2/*配置UART用于RX中断*/IEC0BIT。U1RXYE=1;/ /在接收允许的IPC2BIT.U1RXIP=1;//RX中断优先级IEC0BIT.U1TCHY=0;/ /在TX上中断不允许IFS0BITS。U1RXIF=0;/ /清除中断标志U1SistIt.URX。IsEL=1;//当任何字符接收返回TreErd时;} ValueAyAtditTyx((NoAutoApple PSV))U1RXBuffE(空隙){/*清除中断标志*/IFS0BITI. U1RXIF=0;/*缓冲区中的进程字节*/CutchDRSDS55RX();} CurkExtRSDRS45RX(空隙){chuARTSH();而(U1Stest.UrxDa)//如果AN RS485字节已收到{RS485RXBuffelySub(U1RxReg);}返回;}
以上来自于百度翻译
以下为原文
Hello,
I'm trying to use a PIC24EP64GP202 UART1 to read using the RX interrupts. It only seems to read once then will never read again. It's almost like the interrupt flag won't clear.
The messages I'm expecting to receive are between 7 and 135 bytes. So I basically just want to continuously flush the UART into a circular buffer.
Can someone help me figure out what's going on?
bool8_t UART_Initialize( void )
{
IEC0 = 0x0000; // Disable all
IEC1 = 0x0000;
IEC2 = 0x0000;
IEC3 = 0x0000;
IEC4 = 0x0000;
LATA = 0xffff; // All hi
LATB = 0xf7ff; // All hi except RS485TXEN
TRISA = 0xffff; //
TRISB = 0xb0ff; // All inputs except SCL, SDA, RS485TX, RS485TXEN, TOKENO
ANSELA = 0x0000; // All ANx inputs set as digital I/O
// UART1 Perif Pin Select (PPS)
RPINR18bits.U1RXR = 44; // Assign U1RX to RPI44(RB12)
TRISBbits.TRISB12 = 1; // as an input
RPOR4bits.RP42R = 1; // Assign U1TX to RP42(RB10)
TRISBbits.TRISB10 = 0; // as an output
U1MODE = 0xa800; // Set UART1 : Enable UART1, Halt in Idle Mode
// U1MODE = 0xa808; // ...Hi-Speed
// : RX Enabled, RTS* Simplex Mode
// : No Wakeup, Loopback Disabled, Baudrate Measure Disabled, RX Idle Hi,
// : LoSpeed Mode, 8 Bit, 1 Stop Bit
U1BRG = 7; // : 57.6K Baud
U1STA = 0x0400; // : TX Enabled, Break Disabled, Addr Detect Disabled
U2MODE = 0x0000; // Set UART2 : Disable UART2
/* Configure the UART for RX interrupts */
IEC0bits.U1RXIE = 1; // interrupt on reception allowed
IPC2bits.U1RXIP = 1; // rx interrupt priority
IEC0bits.U1TXIE = 0; // interrupt on tx not allowed
IFS0bits.U1RXIF = 0; // clear interrupt flag
U1STAbits.URXISEL = 1; // interrupt when any char received
return TRUE_D;
}
void __attribute__((no_auto_psv)) U1RXInterrupt(void)
{
/* Clear the interrupt flag */
IFS0bits.U1RXIF = 0;
/* process bytes in the buffer */
InterruptedRS485RX();
}
void InterruptedRS485RX(void)
{
ChkUARTs();
while (U1STAbits.URXDA) // If an RS485 byte has been received
{
RS485RxBuffer_Set(U1RXREG);
}
return;
}
0