完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好!我在PIC24FJ256GB606设备上工作在中断驱动的UART上。我的代码工作正常,除非UART接收中断第一次被错误触发:例如,主例程是:ISR是:初始化:请参阅附上的图像并考虑如下,1)微控制器在这一点上不需要接收任何东西。我试图运行相同的代码离开RX线打开,我得到了同样的结果。2)这个代码工作正常,如果我禁用接收中断IEC1BITS。U2RXYE=0;
以上来自于百度翻译 以下为原文 Hi Everyone! I am working on interrupt driven UART on PIC24FJ256GB606 device. My code works just fine except UART receive interrupt gets falsely triggered for the first time: e.g. main routine is : int main(){ System_init(); uart_init(); // UART2_PPS RPINR19bits.U2RXR= 21; RPOR13bits.RP26R = 5; TRISGbits.TRISG6 = 1; TRISGbits.TRISG7 = 0; uart_puts("n**********************************************"); uart_puts("nMy project "); uart_puts("n x"); uart_puts("n x"); uart_puts("n"__DATE__); uart_puts("n**********************************************"); return -1; } } ISR is: void __attribute__ ( ( interrupt, no_auto_psv ) ) _U2RXInterrupt( void ) { IFS1bits.U2RXIF = 0; uart_puts("False Trigger"); __delay_ms(1000); } Initialization is: int uart_init() { int status = -1; size_t i; // STSEL 1; IREN disabled; PDSEL 8N; UARTEN enabled; RTSMD disabled; USIDL disabled; WAKE disabled; ABAUD disabled; LPBACK disabled; BRGH enabled; URXINV disabled; UEN TX_RX; U2MODE = 0x8008; // OERR NO_ERROR_cleared; URXISEL RX_ONE_CHAR; UTXBRK COMPLETED; UTXEN disabled; ADDEN disabled; UTXISEL0 TX_ONE_CHAR; UTXINV disabled; U2STA = 0x0000; // U2TXREG 0; U2TXREG = 0x0000; // BaudRate = 9600; Frequency = 4000000 Hz; U2BRG 103; U2BRG = 0x0067; // ADMADDR 0; ADMMASK 0; U2ADMD = 0x0000; rb_attr_t attr = {sizeof(_rbmem[0]), ARRAY_SIZE(_rbmem), _rbmem}; if (ring_buffer_init(&_rbd, &attr) == 0) { U2MODEbits.UARTEN = 1; // And turn the peripheral on U2STAbits.UTXEN = 1; //UART2 Transmit Enable IFS1bits.U2RXIF = 0; //_U2RXIF = 0; IEC1bits.U2RXIE = 1; //_U2RXIE = 1; status = 0; } return status; } please see the image attached and consider following, 1) microcontroller is not expected to receive anything at this point. i tried to run the same code leaving rx line open i got the same result. 2) This code works just fine if i disable the receive interrupt IEC1bits.U2RXIE = 0; Attached Image(s) |
|
相关推荐
6个回答
|
|
RX引脚在RP21?RP21具有模拟功能C1IND。如果你不改变为数字输入,RX总是读为0。这将作为UART接收机的开始位。
以上来自于百度翻译 以下为原文 RX pin is at RP21? RP21 has analog function C1IND. If you don't change to digital input, RX is always read as 0. This will be as Start-Bit for the UART receiver. |
|
|
|
Weydert谢谢你的回复。是的,对不起,我已经禁用模拟功能。我也能收到。如果我从我的PC上发送ABCDEF,我将收到ABCDE。现在是0xFF,这是错误的读数。但是从第二次以后我可以读取从pcI发送的任何东西,我正在使用ftdi USB到UART桥和realterm软件与pic通信。
以上来自于百度翻译 以下为原文 Weydert thank you for the reply. Yes I m sorry I have disabled analog function. I am able to receive as well. if I send ABCDEF from my my PC. I will receive ÿABCDE. now ÿ is 0xFF which is false reading. However from second time onwards I can read whatever is sent from pc I am using ftdi USB to UART bridge and realterm software to communicate with pic |
|
|
|
先跑,是的。也许,在接通电源后稍等一会儿再发送等,给线路一些时间稳定下来。丢弃第一个字符…
以上来自于百度翻译 以下为原文 First run, yep. Maybe, wait a little bit after power on before transmitting etc, to give time to the lines for stabilizing. And, discard first char... |
|
|
|
嗨,UART的初始化代码看起来像是MCC生成的。尽管如此,它演示了糟糕的编程实践,因为它在其他设置操作之前启用了模块。我已经看过了。数据表部分19.2以8位数据模式传输,部分19.3以8位数据模式或9位数据模式接收:1。设置UARTX: A)为数据、奇偶校验和停止位编写适当的值。b)将适当的波特率值写入UXBRG寄存器。c)设置发送和接收中断使能和优先级位。2。启用UARTX。2。通过设置URXEN位(UxSTA<12>)启用UARTx。此外,在生成的代码中,对TXREG=0000有写入;这不仅清空寄存器,还可以对发射机FIFO寄存器中的第一个字节的传输进行排队。
以上来自于百度翻译 以下为原文 Hi, The initialization code for UART look like it may have been generated by MCC. Despite this, it demonstrate bad programming practice, in that it enable the module before other setup operations. What is done, is contrary to what is recommended in datasheet for this device, and for all other devices that I have looked at. Datasheet section 19.2 Transmitting in 8-Bit Data Mode and section 19.3 Receiving in 8-Bit or 9-Bit Data Mode: 1. Set up the UARTx: a) Write appropriate values for data, parity and Stop bits. b) Write appropriate baud rate value to the UxBRG register. c) Set up transmit and receive interrupt enable and priority bits. 2. Enable the UARTx. 2. Enable the UARTx by setting the URXEN bit (UxSTA<12>). Also, in the generated code, there is a write to TXREG = 0000; This do not only clear the register, it may also queue transmission of a first byte in the transmitter FIFO register. Regards, Mysil |
|
|
|
还有…
以上来自于百度翻译 以下为原文 and... //uart_init(); // UART2_PPS RPINR19bits.U2RXR= 21; RPOR13bits.RP26R = 5; TRISGbits.TRISG6 = 1; TRISGbits.TRISG7 = 0; uart_init(); // <---- move here |
|
|
|
你好,CinziaG女士,谢谢!我能摆脱错误的扳机!“永远写信给LAT.…不,拜托,我们已经受够了:D“LOL:真的!Mysil先生,谢谢!是的,这个代码是MCC生成的,我纠正了代码,它解决了假NULL读取!
以上来自于百度翻译 以下为原文 Hi Ms. CinziaG Thank you! I was able to get rid of false trigger! and "Always write to LAT... no please, we've had enough :D" LoL: true that! Mr. Mysil Thank you! Yes this code was MCC generated and I corrected the code and it resolved the the false null read! |
|
|
|
只有小组成员才能发言,加入小组>>
5184 浏览 9 评论
2005 浏览 8 评论
1932 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3179 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2230 浏览 5 评论
739浏览 1评论
626浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
511浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
637浏览 0评论
535浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-28 12:51 , Processed in 1.397743 second(s), Total 89, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号