UART中断无限循环微芯片
UART interrupt infinite loop microchip
您好,我正在使用 PIC32MX370F512L 并遇到 "problem",实际上,这不是一个真正的问题,因为我已经修复了它,但我不明白为什么我的修复工作。我给你看一段代码然后解释一下:
void __ISR(_UART_4_VECTOR, ipl1) Uart4Handler(void) {
putU4_string("Entered Interrupt\n\r"); //This command send to my terminal the Text entered
int c = U4RXREG; // PAY ATTENTION TO THIS LINE <-------
IFS2bits.U4RXIF = 0; //Clear the Uart4 interrupt flag.
putU4_string("Exit Interrupt\n\r");
}
如果我不输入 int c = U4RXREG;然后中断被连续调用,我不能再清除 IFS2bits.U4RXIF
这些是我的 UART 设置:
void UART_Config_Interrupt() {
INTEnableSystemMultiVectoredInt(); //from plib.h
IPC9bits.U4IP = 1; //Priority
IPC9bits.U4IS = 3; //Sub-priority
IFS2bits.U4RXIF = 0; //Interrupt flag putted at zero
IFS2bits.U4TXIF = 0;
IEC2bits.U4RXIE = 1; //Enable RX interrupt
}
void UART_Config_Uart(int baud) {
U4MODEbits.ON = 0;
U4MODEbits.SIDL = 0;
U4MODEbits.IREN = 0;
U4MODEbits.RTSMD = 0;
U4MODEbits.UEN0 = 0;
U4MODEbits.UEN1 = 0;
U4MODEbits.WAKE = 0;
U4MODEbits.LPBACK = 0;
U4MODEbits.ABAUD = 0;
U4MODEbits.RXINV = 0;
U4MODEbits.PDSEL1 = 0;
U4MODEbits.PDSEL0 = 0; //8 bit data NO parity
U4MODEbits.STSEL = 0; //1 stop bit
U4MODEbits.BRGH = 0;
/*Configure baudRate
*Source: http://ww1.microchip.com/downloads/en/DeviceDoc/61107F.pdf
*/
UartBrg = (int) (((float) PbusClock / (16 * baud) - 1) + 0.5);
U4BRG = UartBrg;
U4STAbits.UTXEN = 1;
U4STAbits.URXEN = 1;
U4MODEbits.ON = 1;
}
void UART_Config_Pins() {
TRISFbits.TRISF12 = 0; //TX as digital output
RPF12R = 2; // 0010 U4TX ? Mapping U4TX t o RPF12 ;
TRISFbits.TRISF13 = 1; // RX as digital input
U4RXR = 9; // 1001 RF13 ? Mapping U4RX t o RPF13
}
我真正的问题是在哪里可以检索到这些信息?我怎么知道在清除标志之前我必须 int c = U4RXREG。
这是数据-sheethttp://ww1.microchip.com/downloads/en/DeviceDoc/61107F.pdf
我能找到的唯一与该主题相关的信息是在第 21.13、26.1.1 和 21.6.3 节中,但我自己实在想不通。有人可以告诉我应该如何读取此数据-sheet 以检索此信息吗?例如:
您搜索的信息位于第 X 页第 Y 行,他们的意思是这样说...
我个人认为它可以在第 21 页,因为他们说:
pg21第21.6.3节的一段文字:
====
这意味着,要在清除相应的 UxRXIF 标志位之前清除这些模块的中断,用户应用程序必须确保
URXISEL 控制位指定的中断条件不再为真。
====
如果是,有人可以解释为什么吗?或者你是怎么理解的?
谢谢:)
U4XREG
定义为:
#define U4RXREG PIC32_R (0x6230) /* Receive */
#define PIC32_R(a) (0x1F800000 + (a))
在 pic32mx.h
(参见 https://github.com/sergev/pic32sim/blob/master/pic32mx.h)
这会读取一个寄存器。很可能,作为读取寄存器的结果,芯片重置了它的中断状态。
我觉得你需要看看这部分数据sheet:
For UART modules having 8-level-deep FIFO, an interrupt is generated when the interrupt
condition specified by the URXISEL control bits is true. This means, to clear an interrupt for these
modules before clearing the corresponding UxRXIF flag bit, the user application must ensure that
the interrupt condition specified by the URXISEL control bits is no longer true.
连同这部分:
For 8-level deep FIFO UART modules:
11 = Reserved; do not use
10 = Interrupt flag bit is asserted while receive buffer is 3/4 or more full (i.e., has 6 or more data
characters)
01 = Interrupt flag bit is asserted while receive buffer is 1/2 or more full (i.e., has 4 or more data
characters)
00 = Interrupt flag bit is asserted while receive buffer is not empty (i.e., has at least 1 data character)
这意味着您必须从接收缓冲区中读取一些数据才能清除中断条件。因此你需要:
int c = U4RXREG;
您好,我正在使用 PIC32MX370F512L 并遇到 "problem",实际上,这不是一个真正的问题,因为我已经修复了它,但我不明白为什么我的修复工作。我给你看一段代码然后解释一下:
void __ISR(_UART_4_VECTOR, ipl1) Uart4Handler(void) {
putU4_string("Entered Interrupt\n\r"); //This command send to my terminal the Text entered
int c = U4RXREG; // PAY ATTENTION TO THIS LINE <-------
IFS2bits.U4RXIF = 0; //Clear the Uart4 interrupt flag.
putU4_string("Exit Interrupt\n\r");
}
如果我不输入 int c = U4RXREG;然后中断被连续调用,我不能再清除 IFS2bits.U4RXIF
这些是我的 UART 设置:
void UART_Config_Interrupt() {
INTEnableSystemMultiVectoredInt(); //from plib.h
IPC9bits.U4IP = 1; //Priority
IPC9bits.U4IS = 3; //Sub-priority
IFS2bits.U4RXIF = 0; //Interrupt flag putted at zero
IFS2bits.U4TXIF = 0;
IEC2bits.U4RXIE = 1; //Enable RX interrupt
}
void UART_Config_Uart(int baud) {
U4MODEbits.ON = 0;
U4MODEbits.SIDL = 0;
U4MODEbits.IREN = 0;
U4MODEbits.RTSMD = 0;
U4MODEbits.UEN0 = 0;
U4MODEbits.UEN1 = 0;
U4MODEbits.WAKE = 0;
U4MODEbits.LPBACK = 0;
U4MODEbits.ABAUD = 0;
U4MODEbits.RXINV = 0;
U4MODEbits.PDSEL1 = 0;
U4MODEbits.PDSEL0 = 0; //8 bit data NO parity
U4MODEbits.STSEL = 0; //1 stop bit
U4MODEbits.BRGH = 0;
/*Configure baudRate
*Source: http://ww1.microchip.com/downloads/en/DeviceDoc/61107F.pdf
*/
UartBrg = (int) (((float) PbusClock / (16 * baud) - 1) + 0.5);
U4BRG = UartBrg;
U4STAbits.UTXEN = 1;
U4STAbits.URXEN = 1;
U4MODEbits.ON = 1;
}
void UART_Config_Pins() {
TRISFbits.TRISF12 = 0; //TX as digital output
RPF12R = 2; // 0010 U4TX ? Mapping U4TX t o RPF12 ;
TRISFbits.TRISF13 = 1; // RX as digital input
U4RXR = 9; // 1001 RF13 ? Mapping U4RX t o RPF13
}
我真正的问题是在哪里可以检索到这些信息?我怎么知道在清除标志之前我必须 int c = U4RXREG。
这是数据-sheethttp://ww1.microchip.com/downloads/en/DeviceDoc/61107F.pdf
我能找到的唯一与该主题相关的信息是在第 21.13、26.1.1 和 21.6.3 节中,但我自己实在想不通。有人可以告诉我应该如何读取此数据-sheet 以检索此信息吗?例如:
您搜索的信息位于第 X 页第 Y 行,他们的意思是这样说...
我个人认为它可以在第 21 页,因为他们说:
pg21第21.6.3节的一段文字:
====
这意味着,要在清除相应的 UxRXIF 标志位之前清除这些模块的中断,用户应用程序必须确保 URXISEL 控制位指定的中断条件不再为真。
====
如果是,有人可以解释为什么吗?或者你是怎么理解的?
谢谢:)
U4XREG
定义为:
#define U4RXREG PIC32_R (0x6230) /* Receive */
#define PIC32_R(a) (0x1F800000 + (a))
在 pic32mx.h
(参见 https://github.com/sergev/pic32sim/blob/master/pic32mx.h)
这会读取一个寄存器。很可能,作为读取寄存器的结果,芯片重置了它的中断状态。
我觉得你需要看看这部分数据sheet:
For UART modules having 8-level-deep FIFO, an interrupt is generated when the interrupt condition specified by the URXISEL control bits is true. This means, to clear an interrupt for these modules before clearing the corresponding UxRXIF flag bit, the user application must ensure that the interrupt condition specified by the URXISEL control bits is no longer true.
连同这部分:
For 8-level deep FIFO UART modules:
11 = Reserved; do not use
10 = Interrupt flag bit is asserted while receive buffer is 3/4 or more full (i.e., has 6 or more data characters)
01 = Interrupt flag bit is asserted while receive buffer is 1/2 or more full (i.e., has 4 or more data characters)
00 = Interrupt flag bit is asserted while receive buffer is not empty (i.e., has at least 1 data character)
这意味着您必须从接收缓冲区中读取一些数据才能清除中断条件。因此你需要:
int c = U4RXREG;