问题描述
我正在使用 PIC32MX370F512L 并遇到了问题",实际上,这不是真正的问题,因为我已经修复了它,但我不明白为什么我的修复有效.我给你看一段代码然后解释:
Hi I'm using PIC32MX370F512L and encountered a "problem", in reality, it's not a real problem because I already fixed it, but I can't understand why does my fix work. I Will show you a piece of code then explain:
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
If I DO NOT put the line int c = U4RXREG; then the interrupt is continuously called and I can't no more clear the IFS2bits.U4RXIF
这些是我的 UART 设置:
These are my UART settings:
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.
My real question is WHERE can I retrieve this information? HOW can I know that I MUST int c = U4RXREG before clearing the flag.
这是数据表 http://ww1.microchip.com/downloads/en/DeviceDoc/61107F.pdf
我能找到的与此主题相关的唯一信息是在第 21.13、26.1.1 和 21.6.3 节中,但我真的无法自己弄清楚.有人能告诉我应该如何阅读这个数据表来检索这些信息吗?例如:
The only information near to this topic I can find is in section 21.13, 26.1.1 and 21.6.3 but I really can't figure it out by my self. Can someone tell me how should I read this data-sheet for retrieving this information? For example:
您搜索的信息位于第 X 页的 Y 行,他们的意思是这样说...
The information you search is at page X at line Y and they MEAN this by saying this...
我个人认为它可以在第 21 页上,因为他们说:
I personally think it can be on page 21 because they say:
来自 pg21 第 21.6.3 节的一段文字:
a piece of text from pg21 section 21.6.3:
====
这意味着,要在清除相应的 UxRXIF 标志位之前清除这些模块的中断,用户应用程序必须确保URXISEL 控制位指定的中断条件不再为真.
This means, to clear an interrupt for these modules before clearing the corresponding UxRXIF flag bit, the user application must ensure thatthe interrupt condition specified by the URXISEL control bits is no longer true.
====
如果是,有人能解释一下原因吗?或者你怎么解释?
If yes, can someone explain why? Or how do you interpret this?
谢谢:)
推荐答案
我觉得你需要看看这部分数据表:
I think you need to look at this part of the data sheet:
对于具有 8 级深度 FIFO 的 UART 模块,中断时产生中断URXISEL 控制位指定的条件为真.这意味着,清除这些中断在清除相应的 UxRXIF 标志位之前,用户应用程序必须确保URXISEL 控制位指定的中断条件不再为真.
连同这部分:
对于 8 级深度 FIFO UART 模块:
11 = 保留;不要使用
11 = Reserved; do not use
10 = 当接收缓冲区已满 3/4 或更多时(即,有 6 个或更多数据字符)
10 = Interrupt flag bit is asserted while receive buffer is 3/4 or more full (i.e., has 6 or more data characters)
01 = 当接收缓冲区满 1/2 或更多时(即,有 4 个或更多数据字符)
01 = Interrupt flag bit is asserted while receive buffer is 1/2 or more full (i.e., has 4 or more data characters)
00 = 当接收缓冲区不为空(即,至少有 1 个数据字符)时中断标志位被置位
00 = Interrupt flag bit is asserted while receive buffer is not empty (i.e., has at least 1 data character)
这意味着您必须从接收缓冲区中读取一些数据才能清除中断条件.因此你需要:
This means that you have to read some data out of the receive buffer in order to clear the interrupt condition. Consequently you need:
int c = U4RXREG;
这篇关于UART中断无限循环微芯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!