完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,我正试图通过UART 2与RN2443模块进行对话,并且我使用UART 1进行调试(使用PC上的CuteCoM),发生的是,我向模块发送命令,模块响应(我看到使用范围的在线上的响应),但是UART2RX中断没有关闭。这是奇怪的,因为当我使用相同的代码(除了UART 1),中断工作,我可以收到我的答复。由于两个UART的初始化都是相同的,所以我不知道问题是什么。Edj:我注意到现在中断了,但是它退出了中断,因为U2Stest.FER被设置了。在我可以像平常一样解码消息的范围内,所有的比特似乎都在这里,所以问题实际上变成:为什么U2Stest.FER设置为我接收的所有字节?没有一个字节通过。这只发生在来自微芯片的RN2443模块的接收消息上。当我在EDIti AM的UART一端发送消息到设备上时,在PIC24FV16KM202控制器上使用UART2和UART 1都不会发生这种情况。PIC24通过发现HTTP://www. McCudio.com……ASPX与我的PC连接。PARNONO=DMS24013-2。这里,我使用初始化I/O的代码:现在我分别用代码初始化我的UART:中断对于UART来说是完全相同的,见下文;
以上来自于百度翻译 以下为原文 Hi, I am trying to talk to a RN2483 module through UART 2, and I use UART 1 for debugging (using cutecom on pc) What happens is that I send a command to the module, the module responds (I see the response on the line using a scope), but the UART2RX interrupt doesn't go off. This is strange because when I use the same code (except for UART 1) the interrupt does work and I can receive my response. As the initialization for both UART are the same, I have no clue what the problem is. EDIT: I noticed now the interrupt does trigger, but it exits the interrupt right away because the U2STAbits.FERR is set. On the scope i can decode the message like normal, all bits seem to be here, so the question really turns into: Why is U2STAbits.FERR set for ALL BYTES i receive? Not a single byte comes through. This only occurs on the received messages from the RN2483 module from Microchip. This doesn't occur when I send messages to the device from my PC on uart 1. END OF EDIT I am using both UART2 and UART 1 on the PIC24FV16KM202 controller. The PIC24 is connected with my PC through the programmer found http://www.microchip.com/...aspx?PartNO=DM240013-2 here. The code i use for initializing my I/O: ANSA = 0x0000; // set pin mode to digital TRISA = 0x0000; // set pin function all to output ANSAbits.ANSA2 = 1; // RA2 = OSCI TRISAbits.TRISA2 = 1; // RA2 = OSCI LATBbits.LATB0 = 1; // master TX LATBbits.LATB7 = 1; // Diver TX // set pin function PORT B (input = 1 / output = 0) // ANSB = 0x0000; // set pin mode to digital HLVDCONbits.HLSIDL = 1; //TRISB = 0xFFFF; // set pin function all to output TRISBbits.TRISB0 = 0; TRISBbits.TRISB7 = 0; TRISBbits.TRISB13 = 0; // RB13 = reset pin (Output) IFS1 = 0x0000; // Reset all interrupts IFS2 = 0x0000; // Reset all interrupts IFS3 = 0x0000; // Reset all interrupts IFS4 = 0x0000; // Reset all interrupts IFS5 = 0x0000; // Reset all interrupts IFS6 = 0x0000; // Reset all interrupts INTTREG = 0b0000000000000000; Now I initialize both my uarts respectively with the code: void init_rn2483_uart() { U2MODEbits.UARTEN = 1; // Enable UART U2MODEbits.STSEL = 0; // 1-stop bit U2MODEbits.PDSEL = 0; // No Parity, 8-data bits U2MODEbits.ABAUD = 0; // Auto-Baud disabled U2MODEbits.BRGH = 0; // Standard-Speed mode U2MODEbits.WAKE = 0; // Wake up after start bit U2BRG = BAUD_TO_BRG(9600); U2MODEbits.USIDL = 1; // Stop in idle mode U2MODEbits.UEN = 0; // Only use TX and RX U2STAbits.URXISEL = 1; // Interrupt after a RX character is received; U2STAbits.UTXISEL0 = 1; // UARTx Transmission Interrupt Mode = Interrupt when the last character is shifted out of the Transmit Shift Register; U2STAbits.UTXISEL1 = 0; IEC1bits.U2TXIE = 0; // Disable UART TX interrupt IEC1bits.U2RXIE = 1; // Enable UART RX interrupt IPC7bits.U2TXIP = 5; // UART interrupt priority (0 = lowest, 7 = highest) U2STAbits.UTXEN = 1; // Enable UART TX } void init_debug_uart() { U1MODEbits.STSEL = 0; // 1-stop bit U1MODEbits.PDSEL = 0; // No Parity, 8-data bits U1MODEbits.ABAUD = 0; // Auto-Baud disabled U1MODEbits.BRGH = 0; // Standard-Speed mode U1MODEbits.WAKE = 0; // Wake up after start bit U1BRG = BAUD_TO_BRG(baudrate); U1MODEbits.USIDL = 1; // ???? in idle mode U1MODEbits.UEN = 0; // Only use TX and RX U1STAbits.URXISEL = 1; // Interrupt after a RX character is received; U1STAbits.UTXISEL0 = 1; // UARTx Transmission Interrupt Mode = Interrupt when the last character is shifted out of the Transmit Shift Register; U1STAbits.UTXISEL1 = 0; IEC0bits.U1TXIE = 0; // Disable UART TX interrupt IEC0bits.U1RXIE = 1; // Enable UART RX interrupt IPC3bits.U1TXIP = 5; // UART interrupt priority (0 = lowest, 7 = highest) U1MODEbits.UARTEN = 1; // Enable UART U1STAbits.UTXEN = 1; // Enable UART TX } The interrupt is exactly the same for both uarts, see below; void _ISR __attribute__((no_auto_psv)) _U1RXInterrupt(void) { IFS0bits.U1RXIF = 0; // Clear Interrupt flag if(U1STAbits.FERR == 1) { // Framing error U1STAbits.FERR = 0; return; } rx_in_debug = (U1RXREG & 0xFF); // Store char in buffer if(U1STAbits.OERR == 1) { U1STAbits.OERR = 0; // Reset error } } void _ISR __attribute__((no_auto_psv)) _U2RXInterrupt(void) { IFS1bits.U2RXIF = 0; // Clear RX Interrupt flag if(U2STAbits.FERR == 1) { // Framing error U2STAbits.FERR = 0; return; } rx_in = (U2RXREG & 0xFF); // Store char in buffer if(U2STAbits.OERR == 1) { U2STAbits.OERR = 0; // Reset error } } |
|
相关推荐
4个回答
|
|
与ORR不同,它必须用软件清除,FRR是只读的。换句话说,您必须读取RXRG来清除FER,否则一旦设置了FRR,它就永久设置。参考:数据表的寄存器15-2中的描述。所以,ISR可以这样做……读取RX寄存器。然后,检查和处理错误条件。如果没有错误,那么在临时变量中做你需要做的任何事情。不管怎样,FRR是如何设置的?取决于连接到UART RX PIN,以及如何(以及何时)另一端被初始化来驱动RX PIN。(U2RX引脚与PGEC1共享。也许这会影响它。)我的初始化代码通常做一个哑读,清除任何可以被软件清除的错误。或者,在“另一端”启用并开始发送之前,接收到的信号逻辑电平为零。这可能导致框架错误和超载错误。或者别的什么……,戴夫。
以上来自于百度翻译 以下为原文 Unlike OERR, which must be cleared by software, FERR is read-only. In other words... You must read the RXREG to clear FERR, otherwise once FERR is set, it remains set forever. Reference: Description in REGISTER 15-2 of the data sheet. So, maybe the ISRs can go something like this...
Anyhow... How does FERR get set in the first place? Depends on what is connected to the UART RX pin, and how (and when) the Other End is initialized to drive that RX pin. Perhaps it gets set when the UART is initialized. (The U2RX pin is shared with PGEC1. Maybe that affects it.) My initialization code usually does a dummy read and clears whatever errors can be cleared by software. Or maybe the received signal logic level is zero before the "Other End" gets enabled and starts sending. This can cause framing errors and overrun errors. Or something else... Regards, Dave |
|
|
|
您好,当您使用MICRODSICK FPIC24F16KM202时,示意图显示,U2RX与PGEC1和U2TX共享,与PGED1:HTTP:/WW1.MICCHIP.COM/DIXBOSS/En/DeVICECD/OC5002142A.PDFSO,如果您需要使用U2改变开关S3,使用PGEC3和PGED3(但您将丢失引脚RB5)。NB:你还需要改变配置位来使用PGEC3/PGED3,否则你将无法调试…
以上来自于百度翻译 以下为原文 Hi, As you are using the Microstick for PIC24F16KM202, the schematic shows that U2RX is shared with PGEC1 and U2TX shared with PGED1 : http://ww1.microchip.com/downloads/en/DeviceDoc/50002142a.pdf So, if you need to use U2 change the switch S3 to use PGEC3 and PGED3 (you will however lose the pins RB5 and RB6). NB : you will also need to change the configuration bits to use PGEC3/PGED3 otherwise you will not be able to debug... Regards |
|
|
|
嗨,谢谢你的回复,我现在取得了很大的进步。我确实注意到错误是只读的,它指定了当前在TrxReg寄存器中的字符的错误。但是我忘了把它拿走。我还测试了我的代码没有返回,一切似乎工作良好,除了设置的费尔寄存器。然而,我认为你的步骤1, 2, 3会出错,因为你在步骤1清除错误,导致步骤2永远不会发现错误。但是我明白了。是的,我使用的是PGEX3I,这是因为RN2443模块(连接到UART2)启动消息。初始化UART后,我重新设置模块。接着有一个启动消息(57600波特,我完全忘记了),之后我发送了一个AutoBoD消息,将波特率转换为9600,在此之后,我似乎不再有帧错误。我认为这是由启动消息引起的,我能安全地忽略帧错误吗?问候,Weffel
以上来自于百度翻译 以下为原文 Hi, Thanks for the responses, I made a lot of progress now. I did indeed notice that the error is read-only, that is specifies the error for the character currently in the RXREG register. I forgot to remove it however. I also tested my code without the return and everything seemed to work fine, except for the FERR register being set. I think however that your step 1, 2, 3 will go wrong since you clear the error at step 1, resulting in step 2 never finding an error? But i get the idea. yes, I'm using the PGEx3 I think it is due to the RN2483 module (connected to UART2) start-up message. I reset the module right after initializing the UART. Then there follows a start-up message (on 57600 baud, which i totally forgot) after which I send an autobaud message to switch the baudrate to 9600, after which i no longer seem te get Frame errors. Am i correct to assume this is caused by the startup message and can I safely ignore the frame error? Regards, Weffel |
|
|
|
你当然是对的。对不起的。我很高兴你能克服。如果你不能在57600点开始工作,我不知道你还能做什么。如果你在发送AutoBood消息后不会出错,那么你在做生意,这是最好的。
以上来自于百度翻译 以下为原文 You are, of course, correct. Sorry. I'm glad you were able to overcome. Surely. If you can't operate at 57600 initially, I don't know what else you can do. If you don't get errors after you send the autobaud message, you are in business, and that's the best it's going to get. Regards, Dave |
|
|
|
只有小组成员才能发言,加入小组>>
5243 浏览 9 评论
2035 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3208 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2258 浏览 5 评论
778浏览 1评论
669浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
597浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
679浏览 0评论
577浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 08:47 , Processed in 1.641861 second(s), Total 84, Slave 68 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号