完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好!我们正在使用PIC24FJ128GA310代码编程PIC24FJ256GA705处理器(在最后一个PIC中工作得很好)。我们研究了两个不同的问题:1。PIC只是使用UART2模块的TX.2打印一些字符串。PIC使用UART2模块的RX接收字符并使用相同的U2 MODUL的TX打印回原件PIC24FJ128GA310:对于第一个问题,由于我们没有解决的UTXBF的一些问题,以前的代码在新的处理器中不起作用。在代码发送5个字符之后,UTXBF永远保持完整(UTXBF=1)。我们通过将代码更改为以下代码来解决这个问题:这个代码对于TX来说是很好的。在第二个问题中,我们还没有设法使它工作。我们尝试使用与第一种情况相同的方法:不使用RX中断。但不幸的是,我们没有收到任何字符。使用的代码如下:有人知道为什么中断在我们的情况下不起作用吗?我们想使用它们,但不是强制性的。否则,有人知道如何使用UART而不需要RX和TX中断吗?提前感谢。
以上来自于百度翻译 以下为原文 Hi everyone! We are programming a PIC24FJ256GA705 processor using PIC24FJ128GA310 code (which works fine in this last PIC). We have studied two different problems: 1. The pic just prints some strings using UART2 module's TX. 2. The pic receives characters using UART2 module's RX and print them back using the same U2 modul's TX. Original code for pic24fj128ga310: void InitUART2(void) { U2MODEbits.UARTEN = 0; U2BRG = 102; IFS1bits.U2TXIF = 0; // Clear the Transmit Interrupt Flag IEC1bits.U2TXIE = 1; // Enable Transmit Interrupts IFS1bits.U2RXIF = 0; // Clear the Recieve Interrupt Flag IEC1bits.U2RXIE = 1; // Enable Recieve Interrupts U2MODEbits.UARTEN = 1; U2STAbits.UTXEN = 1; } int putU2(int c) { while (U2STAbits.UTXBF); U2TXREG = c; return c; } void __attribute__ ((interrupt, no_auto_psv)) _U2RXInterrupt(void) { IFS1bits.U2RXIF = 0; volatile int data; do { data = U2RXREG; } while (U2STAbits.URXDA != 0); putU2(data); } void __attribute__ ((interrupt, no_auto_psv)) _U2TXInterrupt(void) { IFS1bits.U2TXIF = 0; } For the first problem, this previous code does not work in the new processor due to some problems with UTXBF that we didn't manage to solve. After the code sends 5 characters, the UTXBF stays full (UTXBF = 1) forever. We have solved this issue by changing the code to the following one: U2STAbits.UTXISEL1 = 1; ... IFS1bits.U2TXIF = 0; IEC1bits.U2TXIE = 0; ... int putU2(int c) { while (!_U2TXIF); // wait while Tx buffer full U2TXREG = c; _U2TXIF = 0; return c; } This code works fine for TX. In the second problem, we haven't manage to make it work. We have tried to use the same approach as we did in the first case: not using interruptions for RX. But unfortunatly we do not receive any character. The used code is the following: U2STAbits.UTXISEL1 = 1; ... U2STAbits.URXISEL = 2; ... IFS1bits.U2TXIF = 0; IEC1bits.U2TXIE = 0; IFS1bits.U2RXIF = 0; IEC1bits.U2RXIE = 0; ... int putU2(int c) { while (!_U2TXIF); // wait while Tx buffer full U2TXREG = c; _U2TXIF = 0; return c; } char getU2() { while(!U2STAbits.URXDA); //option 1 //while(!_U2RXIF); //option 2 _U2RXIF = 0; putU2(U2RXREG); return U2RXREG; } Does anybody knows why interruptions do not work in our case? We would like to use them, but is not mandatory. Otherwise, does anybody knows how to use the UART without RX and TX interruptions? Thanks in advance. |
|
相关推荐
2个回答
|
|
我们终于成功了!我们认为问题可能在于缓冲寄存器。在UART TX中,我们有这个循环:代码不会继续,它被卡住了。在UART RX中我们有这个循环:代码被卡住了。所以我们把那些循环去掉了,现在它工作得很好!BTW,如果有人知道为什么这个问题会发生,或者如何用另一种方式来解决它,如果你分享它,那就太好了。
以上来自于百度翻译 以下为原文 We finally managed to make it work!! We think that the problem might be with the Buffer registers. In UART TX we had this loop: while (U2STAbits.UTXBF); // wait while Tx buffer full and the code wouldn't continue, it got stuck. In UART RX we had this loop: do { data = U2RXREG; } while (!_URXDA); and the code got stuck there. So we took those loops away and now it works fine!! BTW, if anybody knows why this problem happens or how to solve it in another way, it would be great if you share it. |
|
|
|
我没有答案,但这里有一些测试可以揭示一些光-可能是有趣的尝试两个解决方案分开的一半。也就是说,尝试保持RX循环(但不是Tx循环),以及VICE-VALSA.也尝试用URXISEL= UTXISEL=0
以上来自于百度翻译 以下为原文 I do not have an answer, but here are some tests which could shed some light - It might be interesting to try both halfs of your solution separately. That is, try keeping the RX loop (but not the Tx loop), and vice-versa. Also, try with URXISEL = UTXISEL = 0 |
|
|
|
只有小组成员才能发言,加入小组>>
5238 浏览 9 评论
2028 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3204 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
778浏览 1评论
666浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
595浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
677浏览 0评论
576浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 10:39 , Processed in 1.429043 second(s), Total 49, Slave 42 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号