完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
您好,我正在尝试使用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; } |
|
相关推荐
19个回答
|
|
|
|
|
|
|
|
|
可能是导致UART关闭的接收错误?
以上来自于百度翻译 以下为原文 Possibly a receive error causing the UART to shut down? |
|
|
|
|
|
空ChkUARTs(空){if(U1Stest.Orr)/ /如果有UART溢出错误,U1Stist.Orr=0;//除去它们,否则数据不是IFS4BIT.U1EIF=0;}它仍然只读取一次。我试着把中断清除到:空格中断中断485Rx(空隙){(U1Stest.UrxDa)/ /如果RS485字节已被刷新,{RS485RxBuffelySub(U1RxReg);TST++;}/*清除中断标志*/IFS0BITS。U1RXIF=0;返回;}
以上来自于百度翻译 以下为原文 void ChkUARTs(void) { if (U1STAbits.OERR) // If there are UART OverRun errors, U1STAbits.OERR = 0; // get rid of them, otherwise data is not IFS4bits.U1EIF = 0; } It still will only read once. I tried moving the interrupt clear to: void InterruptedRS485RX(void) { while (U1STAbits.URXDA) // If an RS485 byte has been recv'd, { RS485RxBuffer_Set(U1RXREG); tst++; } /* Clear the interrupt flag */ IFS0bits.U1RXIF = 0; return; } |
|
|
|
|
|
是的,这些都是我的建议,基本上是这样的。我不确定…这是485行,所以你正确处理“所有权”,即驱动程序启用吗?
以上来自于百度翻译 以下为原文 Yep, those were going to be my suggestions, basically So.. am not sure... This is a 485 line, so are you dealing correctly with the "ownership" i.e. driver-enable? |
|
|
|
|
|
我不知道车主“驱动使能”是什么意思。我有一个例子,使用轮询机制在这个板上工作。所以我知道配线和其他装置正在工作。我把所有东西都初始化正确了吗?
以上来自于百度翻译 以下为原文 I'm not sure what you mean by owner "driver-enable". I have an example working this this board using a polling scheme. So I know the wiring and other devise talking to this are working. Do I have everything initialized correctly? |
|
|
|
|
|
我的意思是,自从我读到“485”之后,我就想到了一个MX48或类似的驱动程序,它必须被设置为TX并返回到RX……但是如果你说所有的事情都是在轮询模式下工作的,那么好吧。不确定你的全部init,但是如果你收到一个字符,那么它看起来就可以了。
以上来自于百度翻译 以下为原文 I mean, since I read about "485", I was thinking about a MAX485 or alike driver that must be set for TX and back to RX... But if you say that everything was working in Polled mode, then ok. Not sure about your full init, but if you receive one char then it seems ok... |
|
|
|
|
|
看起来我有了一个U1EIF。我不知道这意味着什么,显然使用IFS4比特。U1EIF=0;清除它也不起作用。你知道是什么引起的以及如何避免它/清除它吗?这就是UART死亡的原因吗?
以上来自于百度翻译 以下为原文 It looks like I am getting a U1EIF. I don't know what that means, and apparently using IFS4bits.U1EIF = 0; to clear it doesn't work either. Do you know what causes that and how to avoid it/clear it? Is that the cause of the UART dying? |
|
|
|
|
|
我注意到你有“停止在闲置模式”设置。我不太熟悉的设置,因为我从来没有使用它,但这并不意味着你需要重新设置UARTN到1,每次你想再次使用它?你有调试器吗?你能看一下你的UART模式/ STAT寄存器在接收之后的状态吗?也许会告诉你第二次的不同。
以上来自于百度翻译 以下为原文 I noticed you have "Stop in Idle Mode" set. I'm not too familiar with the setting as I've never used it but wouldn't that mean you need to re-set UARTEN to 1 each time you want to use it again? Do you have a debugger? Can you possibly look at the state of your UART mode/stat registers after a reception? Might clue you into what's different the 2nd time around. |
|
|
|
|
|
为了清除旗子,你必须清除中断的来源。在状态寄存器中是否存在任何错误位?ORR?费尔?珀尔?
以上来自于百度翻译 以下为原文 You've got to clear the source of the interrupt in order to clear the flag. Are any of the ERR bits raised in the status register? OERR? FERR? PERR? |
|
|
|
|
|
是的,我正在使用ICD3和MLBX 3.65,XC16V1.31.1,我看看我能不能得到更多关于UARTEN的信息。
以上来自于百度翻译 以下为原文 Yes, I'm using and ICD3 and MLABX 3.65, XC16 v1.31. One moment, I'l see if I can get more info on the UARTEN. |
|
|
|
|
|
是的,也注意到了:我从来没有这样做过,但现在不应该是个问题…
以上来自于百度翻译 以下为原文 Yeah, noticed that too: I never do that, but it should not be an issue now... |
|
|
|
|
|
为了清除旗子,你必须清除中断的来源。在状态寄存器中是否存在任何错误位?ORR?费尔?珀尔?是的,有一个错误。我认为CKUARTSH();我会尝试这样做,但它仍然只读取ONCE.WORD中断DRS485RX(空隙){(U1Stest.UrxDa)/ /如果RS485字节已被刷新,{CKUARTSH());RS485RXBuffelySub(U1RxReg);}/*清除中断标志*/IFS0BITS。U1RXIF=0;返回;}
以上来自于百度翻译 以下为原文 You've got to clear the source of the interrupt in order to clear the flag. Are any of the ERR bits raised in the status register? OERR? FERR? PERR? Yes, there's an OERR. I thought ChkUARTs(); would take care of that so I tried this, but it still will only read once. void InterruptedRS485RX(void) { while (U1STAbits.URXDA) // If an RS485 byte has been recv'd, { ChkUARTs(); RS485RxBuffer_Set(U1RXREG); } /* Clear the interrupt flag */ IFS0bits.U1RXIF = 0; return; } |
|
|
|
|
|
哦,这是超载错误。我假设这是因为中断不超过一次,以允许读取再次发生。
以上来自于百度翻译 以下为原文 Oh it's Overrun Error. I'm assuming that's because the interrupt isn't firing more than once to allow the read to happen again. |
|
|
|
|
|
HMM,清除ORRR应该擦除FIFO,并让您根据PIC34 E FRM清除中断。它注意到RSR中的任何数据都将保留。如果FIFO满了(四个字符),并且第五字符完全接收到UXRSR寄存器,ORR位,则会有7.7.2个接收器错误处理。(UXSTA & lt;1 & gt)将被设置。UXRSR寄存器中的字将被保留,但进一步转移到接收FIFO,UART中断被禁止,只要OER位被设置。用户应用程序必须清除软件中的ORR位,以允许接收更多的数据。他超载,用户应用程序应该首先读取五个字符,然后清除ORR位。如果五个字符可以被丢弃,用户应用程序可以简单地清除ORR位。这有效地重置了接收FIFO,并且所有先前接收的数据丢失。
以上来自于百度翻译 以下为原文 Hmm, Clearing OERR should just wipe the FIFO and let you clear the interrupt according to the PIC34E FRM. It does note that any data in the RSR will remain. 17.7.2 Receiver Error Handling If the FIFO is full (four characters) and a fifth character is fully received into the UxRSR register, the OERR bit (UxSTA<1>) will be set. The word in the UxRSR register will be kept, but further transfers to the receive FIFO, and UART interrupts are inhibited as long as the OERR bit is set. The user application must clear the OERR bit in software to allow further data to be received. If it is desired to keep the data received prior to the overrun, the user application should first read all five characters, then clear the OERR bit. If the five characters can be discarded, the user application can simply clear the OERR bit. This effectively resets the receive FIFO, and all prior received data is lost. |
|
|
|
|
|
我认为ORR是这个问题的结果,但不是原因的一部分。
以上来自于百度翻译 以下为原文 I think the OERR is a result of the problem, but not part of the cause. |
|
|
|
|
|
确实,我想检查一下是什么导致FIFO超支。在什么情况下,代码不会中断来读取FIFO。一旦你在中断中读出FIFO,大概你是从ISR返回的,那么你很快就会从下一个字节进入FIFO中得到另一个中断。有什么能阻碍中断的执行吗?中断的代码的任何部分?有没有其他的中断可以让你保持足够长的时间来防止RX中断被服务?
以上来自于百度翻译 以下为原文 Indeed. I suppose the thing to examine is what's causing the FIFO to overrun. In what situation would the code not interrupt to read the FIFO out. Once you read out the FIFO in the interrupt, presumably you are returning from the ISR then you very shortly afterward get another interrupt from the next byte entering the FIFO. Could something be holding up the execution of the interrupt? Any parts of the code where interrupts are being disabled? Are there any other interrupts that could be holding you up for long enough to prevent the Rx interrupt from being serviced? |
|
|
|
|
|
波特率的计算是否正确?除了UART之外还有其他的中断吗?
以上来自于百度翻译 以下为原文 Are the baud rate calculations correct? Are there additional interrupts from other than the UART? |
|
|
|
|
|
主循环只是在此刻做这件事,而且它不会中断任何其他中断:
以上来自于百度翻译 以下为原文 The main loop is just doing this at the moment, and it's not breaking on any other interrupts: for(;;) { asm("clrwdt"); // ** Kick Watchdog ** ParseHostRecv(RS485CLIENT); __delay_us( 250 ); } And void ParseHostRecv(unsigned char Client) { if(!U1STAbits.URXDA) { // debug spot in code to view with breakpoint RS485BuffIn_test[0] = RS485BuffIn[0]; } return; } |
|
|
|
|
|
我假设波特率是错误的,它不会与轮询一起工作,但我可能错了:*定义FP 40000000α定义BurdRead 57600定义BGVALVE((FP/波特率)/ 16)-1。
以上来自于百度翻译 以下为原文 I assume if the baud rate was wrong, it wouldn't have worked with polling, but I could be wrong: #define FP 40000000 #define BAUDRATE 57600 #define BRGVAL ((FP/BAUDRATE)/16) - 1 |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 06:32 , Processed in 1.327391 second(s), Total 108, Slave 91 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2293