完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,我有一小部分代码,我只是为了测试优先级中断。PIC:18F26K22,内部OSC32 MHz(8xPLL),没有WDT。中断使用:time0(高优先级),USAT RX(低优先级)。Usart:9600 8N1。编译器:XC8 1.37免费模式,MPLAX 3.25 PIC是回声前夕。Ry接收到的字符,以前存储在环形缓冲区中。定时器0中断只是为了测试优先级系统,它比USAT快(这里的定时器溢出并不重要)。PIC正在正确地接收数据(不管使用内部振荡器,没有影响它的漂移),Time0正在正确地触发中断。一切看起来都很好,但是…如果你键入终端,在某些时候你会注意到PIC看起来像重新启动。这种“重置”是随机发生的。当你打字或输入一堆数据后,有时会发生,但它会在某个时候发生。您看到的是“等待输入数据…”(检查代码)。我检查了RCON和STKPTR,寻找可能的复位源,但没有复位的原因。我在数据表中读到,对于低中断上下文不保存,必须在软但XC8编译器手册中完成。正如我所理解的那样,编译器生成用于保存和恢复高优先级和低优先级中断的上下文的代码。我检查了高处,有一堆寄存器被保存,对于低我可以看到一些寄存器被保存和恢复,但我不确定他们是否应该是他们应该是什么。代码以防万一:配置:我试图找到有关的问题在论坛上,但没有找到任何…我不KNO。确切地说,正在发生什么,我的疑虑是关于上下文的,但是我不确定编译器在做什么(或者没有做什么)。有什么想法或建议吗?干杯。
以上来自于百度翻译 以下为原文 Hello. I'm having some troubles with a small piece of code I made just for testing the priority interrupts. PIC: 18F26k22, Internal Osc 32Mhz (8xPLL), No WDT. Interrupts used: Timer0 (high priority), Usart RX (low priority). Usart: 9600 8N1. Compiler: XC8 1.37 Free mode, MPLAX 3.25 The PIC is echoing every received character, previously stored in a ring buffer. Timer 0 interrupt is there just to test the priority system, it's faster than the usart (timer overflow is not important here). PIC is receiving data correctly (regardless using the internal oscillator, there is no drift affecting it), Timer0 is triggering interrupt correctly. Everything looks ok, but ... if you type in the terminal, in some point you notice the PIC look like restarting. This kind of "reset" happens randomly... sometimes happens as soon as you type something or after typing a bunch of data, but it will happen in some point... And what you see is again the "Waiting for incoming data..." (check code). I checked the RCON and STKPTR looking for a possible source of reset, but there is no cause of reset. I read in datasheet that for low interrupt context is not saved and must be done in soft, but XC8 compiler's manual -as far as i understood- says the compiler generate code for saving/restoring the context for both high and low priority interrupts. I checked the high and there's a bunch of registers being saved, and for low I could see some registers being saved and restored but I'm not sure if they are all that they should be. Code just in case: void main(void) { ConfigureOscillator(); //Fosc 32Mhz, from internal osc with PLL... 125ns cycle. Verified. InitApp(); // usual, setting tris registers, all pins digital, no comparators... bla bla.. Verified //configure EUSART 16-bit mode BAUDCON1 = 0b01001000; //open USART 9600 8N1, RX int on Open1USART (USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 64); SPBRGH1 = 3; //all ok here //enable priorities RCONbits.IPEN = 1; //enable USART interrupts PIR1bits.RC1IF = 0; //reset RX pin flag IPR1bits.RC1IP = 0; //no high priority PIE1bits.RC1IE = 1; //RX int enabled //configure TIMER0 T0CONbits.TMR0ON=1; //enable TMR0 T0CONbits.T08BIT=1; //8-bit mode T0CONbits.T0CS=0; //use internal clock T0CONbits.PSA=0; //no prescaler //enable TIMER0 interrupts INTCONbits.TMR0IF = 0; //clear flag INTCON2bits.TMR0IP = 1; //tmr0 high priority int INTCONbits.TMR0IE = 1; //tmr0 int enable //enable high/low priority interrupts INTCONbits.GIEH = 1; INTCONbits.GIEL = 1; putrs1USART("Waiting for incoming data...nr"); while(1) { PIE1bits.RC1IE = 0; //disable RX interrupt for accessing critical resource int data = rx_buffer_get(); PIE1bits.RC1IE = 1; //re-enable RX interrupt if (data != SERIAL_BUFFER_EMPTY) { while( Busy1USART() ); putc1USART((unsigned char)data); } } } void interrupt low_priority usart_rx_isr() { if ( PIR1bits.RC1IF ) { //store incoming data into buffer, no Frame/Overrun check for our human-speed test rx_buffer_put(RCREG1); } } volatile char timer = 0; //for testing void interrupt high_priority timer0_isr() { if ( INTCONbits.TMR0IF ) { //do not reload timer, let it overflow. timer = ~timer; INTCONbits.TMR0IF = 0; //clear flag } } Config: // CONFIG1H #pragma config FOSC = INTIO67 // Oscillator Selection bits (Internal oscillator block) #pragma config PLLCFG = ON #pragma config PRICLKEN = ON // Primary clock enable bit (Primary clock enabled) #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled) #pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled) // CONFIG2L #pragma config PWRTEN = OFF // Power-up Timer Enable bit (Power up timer disabled) #pragma config BOREN = SBORDIS // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled)) #pragma config BORV = 190 // Brown Out Reset Voltage bits (VBOR set to 1.90 V nominal) // CONFIG2H #pragma config WDTEN = OFF // Watchdog Timer Enable bits (WDT is always enabled. SWDTEN bit has no effect) #pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768) // CONFIG3H #pragma config CCP2MX = PORTC1 // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1) #pragma config PBADEN = OFF // PORTB A/D Enable bit (PORTB<5:0> pins are configured as digital I/O on Reset) #pragma config CCP3MX = PORTB5 // P3A/CCP3 Mux bit (P3A/CCP3 input/output is multiplexed with RB5) #pragma config HFOFST = ON // HFINTOSC Fast Start-up (HFINTOSC output and ready status are not delayed by the oscillator stable status) #pragma config T3CMX = PORTC0 // Timer3 Clock input mux bit (T3CKI is on RC0) #pragma config P2BMX = PORTB5 // ECCP2 B output mux bit (P2B is on RB5) #pragma config MCLRE = EXTMCLR // MCLR Pin Enable bit (MCLR pin enabled, RE3 input pin disabled) // CONFIG4L #pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset) #pragma config LVP = ON // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled if MCLRE is also 1) #pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode)) void ConfigureOscillator() { OSCCONbits.IRCF = 0x6; //Configure internal clock frequency: 8Mhz OSCCONbits.SCS = 0x0; OSCTUNEbits.PLLEN = 1; // MPLABX is waiting forever here, HFIOFS is always 0!! while (!OSCCONbits.HFIOFS); } I tried to find something about related issues in the forum but didnt find any... I don't know exactly what is happening, my suspects are about the context but I'm not sure about what the compiler is doing (or not doing). Any idea or suggestion? Cheers. |
|
相关推荐
19个回答
|
|
你没有看门狗或LVP,是吗?显示您的配置设置…
以上来自于百度翻译 以下为原文 You don't have Watchdog or LVP enabled, do you? Show your CONFIG settings.. |
|
|
|
WDT已被禁用,但如果启用,也会出现问题(并且在超时之前进行了软配置和清除)。LVP(CONFIG)确实启用了。我用所有配置更新了原始POST等。
以上来自于百度翻译 以下为原文 WDT is disabled, but the problems also appears if enabled (and propertly configured and cleared in soft before timeout). LVP (config) is indeed enabled. I updated original post with all the configuration, etc. |
|
|
|
好啊!一个启用的LVP可能会导致意外的重置,如果该引脚是浮动的。此外,你的MCLR拉起和稳定?
以上来自于百度翻译 以下为原文 Ok! Well, an enabled LVP may cause unexpected resets if that pin is left floating. Also, is your MCLR pulled up and stable? |
|
|
|
我禁用LVP和MCLR是稳定的,我也尝试禁用它,并使用R3作为数字PIN…甚至更好,我只是尝试了一个不同的PIC 18F420,适应代码和保险丝…同样的问题。我检查了ASCOMLY代码,对于高优先级和低优先级的中断上下文都被保存和恢复。我的脸
以上来自于百度翻译 以下为原文 I disabled LVP and MCLR is stable, I also tried disabling it and using RE3 as digital pin... Even better, I just tried with a different PIC 18F4520, adapting the code and fuses... voila, same problem. I checked assambly code and for both high and low priority interrupt context is saved and restored. : / <= my face |
|
|
|
您的配置显示,您预计PIC运行在32 MHz / 1.9V。这是不规范的。
以上来自于百度翻译 以下为原文 Your config shows you expect that PIC to run at 32 MHz/1.9V. That is out of spec. |
|
|
|
在配置中只有1.9V是BOR…它的工作与5V稳定供应,在范围内的直流特性的频率在数据表中,除非我没有看到什么。请您具体一点好吗?在560页的数据表中很容易省略一些东西…谢谢。
以上来自于百度翻译 以下为原文 The only 1.9V in config is for BOR... and it's working with a 5V stable supply, in range of the DC characteristics for the frequency in the datasheet, unless I'm not seeing something. Could you be more specific, please? It's easy to omitt something in a 560 pages datasheet.... Thanks. |
|
|
|
重新检查你的代码,在启动时,看起来你正在激活USAT IRQ(通过OpenSUART参数)*在设置* IPEN之前,这可能会导致问题…但只有在引导时,您还没有处理USAT RX错误,这可以阻止USAT永远工作。而且,您还没有为那些放置/获取帮助器显示代码。缓冲区溢出/写入“某处”可能是复位的下一个原因!
以上来自于百度翻译 以下为原文 Re-checking your code, at boot it looks like you're activating USART IRQ (via OpenUSART parameters) *before* IPEN is set and this could lead to a problem... but only at boot. You're also not handling USART RX errors, which can stop the USART from working forever. And, you've not shown the code for those put/get helpers. A buffer overflow/write to "somewhere" could be the next reason for a reset! |
|
|
|
32 MHz的最小工作电压为2.7V;因此,在该时钟速度下唯一有效的BOR设置为2.85伏。通过将其设置为1.9V,您允许PIC在BOR电路启动之前熄灭。这可能导致未定义的行为。我不知道这是不是你的问题,但应该改正。
以上来自于百度翻译 以下为原文 The minimum operating voltage for 32 MHz is 2.7V; consequently, the only valid BOR setting at that clock speed is 2.85V. By setting it at 1.9V, you are allowing the PIC to brown out *before* the BOR circuit kicks in. This can result in undefined behavior. I don't know if this is your problem, but it should be corrected. |
|
|
|
Alo,我要检查一下IPEn…我不知道OpenSART处理iPon。剩下的,我知道我没有处理RX中的错误。事实上,对于具有相同代码的18F450(在需要的地方进行修改),我得到了溢出错误。对于缓冲区的GET/PoT帮助器,没有溢出:头增加到溢出,但是,并且将调整缓冲区范围内的值。因为FIFO具有2的尺寸功率,其工作与模数相同。否则,它会失败。唯一可能的“问题”是“RunfIFO.Heal-RunFIFO。尾”。它可能在某个点是否定的,它只会导致在缓冲区中的错误位置写入,但仍然在缓冲区中。同样,操作防止缓冲区外写入。我测试了它,迫使缓冲区填充和验证内存内容…没什么不对。当然,人类错误的幽灵总是在那里…
以上来自于百度翻译 以下为原文 Alo. I'm going to check that about IPEn... I didn't know OpenUsart deals with IPEN. About the rest I know i'm not handling errors in RX. In fact with a 18F450 with same code (adapted where needed), I got Overrun errors. About the get/put helpers for the buffer, there is no overflow: bool rfifo_put(unsigned char data) { if ( (ringFifo.head - ringFifo.tail) >= RFIFO_SIZE) { return RFIFO_FULL; } ringFifo.buffer[ringFifo.head & RFIFO_MASK] = data; //RFIFO_MASK defined as (RFIFO_SIZE-1) ringFifo.head++; return RFIFO_OK; } Head increases until overflow, but the AND will adjust the value in the buffer range. Because the fifo has a size power of 2, the AND operates just like a modulus. Otherwise it would fail. The only possible "issue" is with "ringFifo.head - ringFifo.tail". It could be negative in some point, and it only will lead to writting in an incorrect position in the bufffer, but still in the buffer range. Again the AND operation prevents writing outside the buffer boundaries. I tested it forcing the buffer to fill up and verifuing the memory contents... nothing wrong. Of course the ghost of the human error is always there... |
|
|
|
我认为这不是问题,供应是相当稳定的。但无论如何,这是需要纠正的。谢谢你的指点。
以上来自于百度翻译 以下为原文 I don't think it's the problem, supply is quite stable. But anyway that's something to be corrected. Thanks for pointing that. |
|
|
|
不,OpenSART处理RX IRQ,因为您正在传递一个这样的参数:您将只在稍后设置IPEN,这样就可能发生一个错误的优先级设置的IRQ……然后缓冲区就好了。
以上来自于百度翻译 以下为原文 No, OpenUSART deals with RX IRQ, because you're passing a parameter that says so: and you will set IPEN only later so there could happen an IRQ with the wrong Priority level set... Ok for the buffers, then. |
|
|
|
未处理(和清除)的溢出错误将阻止USAT接收,任何等待接收字符的循环在溢出错误之后都不会完成。而且溢出错误几乎总是指示波特率错误。
以上来自于百度翻译 以下为原文 Overrun errors that are not handled (and cleared) will stop the USART from receiving, any loop that waits for a received character will never complete after an overrun error. Also overrun errors almost always indicate a baud rate error. |
|
|
|
溢出错误几乎总是指示软件错误。帧误差几乎总是指示波特率误差。
以上来自于百度翻译 以下为原文 Overrun errors almost always indicate a software bug. Framing errors almost always indicate a baud rate error. |
|
|
|
你好,你用这个代码做什么?你不读RCRYG1…只把它存储在别处?所以RC1IF位永远不会清晰。只有RCREG1的读取可以使这个标志归零。
以上来自于百度翻译 以下为原文 hello, what are you doing with this code ? void interrupt low_priority usart_rx_isr() { if ( PIR1bits.RC1IF ) { //store incoming data into buffer, no Frame/Overrun check for our human-speed test rx_buffer_put(RCREG1); } } you don't read the RCREG1 ... only store it elsewhere ? so the RC1IF bit is never clear .. only a reading of RCREG1 can zeroed this flag . { char c1; if ( PIR1bits.RC1IF ) { //store incoming data into c1 c1= RCREG1; // read register => clear RC1IF bit rx_buffer_put(c1); // store the result } |
|
|
|
溢出错误几乎总是指示软件错误。帧错误几乎总是表示波特率误差。你是对的,我不应该在星期一早点发布。
以上来自于百度翻译 以下为原文 Overrun errors almost always indicate a software bug. Framing errors almost always indicate a baud rate error. You are so correct, I should not post early on a Monday! |
|
|
|
它确实读取RCREG,然后将RCREG的值传递给RXA BuffSerpPUT。
以上来自于百度翻译 以下为原文 That does read RCREG, then passes the value of RCREG to rx_buffer_put. |
|
|
|
是的,OP的代码,和你建议的替代品,做完全一样的事情。
以上来自于百度翻译 以下为原文 Yes he does. The OP's code, and your suggested alternative, do exactly the same thing. |
|
|
|
是的,OP的代码,和你建议的替代品,做完全一样的事情。
以上来自于百度翻译 以下为原文 Yes he does. The OP's code, and your suggested alternative, do exactly the same thing. Except maybe not as efficiently. |
|
|
|
我敢肯定,即使使用免费编译器,只要“C1”变量不被声明为“易失性”,它将生成完全相同的代码。
以上来自于百度翻译 以下为原文 I'm pretty sure, even with the free compiler, it will generate exactly the same code, so long as the "c1" variable is not declared as "volatile". |
|
|
|
只有小组成员才能发言,加入小组>>
5237 浏览 9 评论
2026 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3201 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
771浏览 1评论
659浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
589浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
671浏览 0评论
571浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 04:12 , Processed in 1.642678 second(s), Total 114, Slave 98 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号