完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
HII正在研究PIC18F2550和PC的通信,使用XBEE S2C。我用XC8编译代码。我用XBee从PC发送一些字符到PIC,然后我发送一个“/R”,PIC必须把我发送的字符还给我。它运行9次迭代,然后崩溃。图像显示了串行控制台(红色字符是PIC的响应)。我已经尝试重置EUSAT,但这似乎不起作用。在第九次迭代中总是失败。我读了一些ORR的帖子,我尝试了很多东西,但没有解决我的问题。注意:这个错误如果包的发送间隔小于1500毫秒,我需要至少每300毫秒发送一次。有人知道它会是什么?=包含和lt;StdIL.H.& Gt;Stry.H.G.//Tyl1L.PrimaMac配置文件PLLDIV=1×PrimaMig-CopDIV= OSC1OLPLL2α-PrAPMA配置文件USBDIV=1//CONT1H H PrimaMac配置文件FoCC=iToScClxxt*谢谢,包括和PIC18F2550。图IOSO=OX//Top2LL Primamatlab配置文件PWRT=Off-PracMaMatg配置BOR==3×Prima配置文件VGREN=OF//CON2H H PracMA配置文件WDT=Off-TracMA配置文件WDTPS=32768//CONTH3H*康康Re//Trac4LL,PrAP4LL=OpGracMA配置,LVP= Off//Pay-Matlab配置,ICPT=Off-PracMA配置,XNT= OF//CONT5Lα,PrimaMac配置,CP0= OFF,TraceMac配置,CP1=Off-Prima配置,CP2=Off-PrimaMatlab配置,CP3= OF//CONT55H*L*PrimaMatlab配置文件WRT1= Off-Trac-Matlab配置文件WRT2= Off-Trac-Matlab配置文件WRT3= OF//CONT66Hα-PrAPMA配置符WRTC=Off-TracMA配置文件WRTB=Off-Trac-Matlab配置文件WRTD=Off-TracMA配置文件EBTR0= OFF TraceMac配置文件EBTR1= OFF TraceMac配置文件EBTR2= Off-TrimaMac配置EBTR3= OF//COMPI.G7H-ApTrimeAgTrb EBTRBB=OX-*定义xTalthFRIQ 400 000易失性INTCONX、COTTX、RxFlag、C;易失性char x(60);易失性char dUm;char CE=48;char BuffTrx〔60〕;Char AUX〔60〕;Chan-CONV〔3〕;int VAL,传感器=0;空中断高优先级接收(空){if(RcStest.Orr){RC〕RC。{Cr==0;RC7=0;} x=RCREG;If(x==13){BuffrTx[Cunx]=Fuffrx[Runx];RxFLAG=1;}否则{Fuffrx[Runx]=x;Buffrtx[Cunx]=FuffRx[Cunx];} Cunx++;} int Adc-(){Adon=1;γ-DelayyMs(1);Gonndot= 1;GoeNndo=(1);稳定。Val=(AdRESH & lt;lt;8)+AdRESL;空主(空隙){//CasoCiONIO/OSK OSCCONDOT.ICOCF=0B111;SCCONBITS=0B10;//端口TrISA=1;PORTB=0;TrISB=1;TrISC= 0B100000;//中断ItCONtiTES。GIE=1;启用Y模式,H或L中断ItCONTITY。/高优先级中断启用ItNCONTITE。PEEAGIGEL=0;/低优先级中断启用AdCON0BITS。CHACS=12;ADCON1=0x00;ADCON2BITS=0B000;ADCON2BITS ACQT= 0B111;ADCON2BITS ADFM=1;PIE1BITS RC1IE=1;/ReCeI;VE中断启用了PIP1BIT.TX1IE=0;和/或发送中断禁用IPR1BITS RC1IP=1;/REST是高优先级PIR1BITS RCIF=0;/RCSTA TXSTA RCSTATE。BAdConnices。WUE=0;BADCONBITS.TXCKP=0;BUCONBITS。BRG16=0;SPRBRG=51;;/51=2400 12=9600 Controx=0;Contx= 0;PoBBITBES.RB7= 1;而(0){Trtx=γ;而(RxFlase==γ){(传感器=;传感器和LT;传感器++){Val= ADC*();;审计委员会V,“%5D”,VAL;SaMPTF(AUX,%S%S,AUX,CONV);AUX〔60〕=0x0A;VAL=0;} SaMPTF(AUX,%S $ rn,AUX);(int z=0;z和lt;60;Z++){TXRGG=AUX[Z];同时(TxStest.TrMT=0);{AUX[Z]=0x00;}}=0;RXFLAG=0;}}
以上来自于百度翻译 以下为原文 Hi I'm working on the communication of a PIC18F2550 and the PC with a pair of xBEE S2C. And I am using xc8 to compile the code. I send some characters to the PIC from the PC with an Xbee then I send a '/r', and the PIC has to return me the characters that I sent. It works for 9 iterations, then it crashes. The image shows the serial console(red characters are the response of the PIC). I´ve tried resetting the EUSART but this doesn´t seem to work. Always fails at the 9th iteration. I´ve read some posts of OERR and I tried a lot of things but nothing has solved my problem. NOTE: This Error presents if the transmit interval of the package is less than 1500 ms. And I need to transmit at least every 300ms. Someone has an idea of what could it be? Thanks #include #include #include #include #include // CONFIG1L #pragma config PLLDIV = 1 #pragma config CPUDIV = OSC1_PLL2 #pragma config USBDIV = 1 // CONFIG1H #pragma config FOSC = INTOSC_XT #pragma config FCMEN = OFF #pragma config IESO = OFF // CONFIG2L #pragma config PWRT = OFF #pragma config BOR = ON #pragma config BORV = 3 #pragma config VREGEN = OFF // CONFIG2H #pragma config WDT = OFF #pragma config WDTPS = 32768 // CONFIG3H #pragma config CCP2MX = ON #pragma config PBADEN = ON #pragma config LPT1OSC = OFF #pragma config MCLRE = OFF // CONFIG4L #pragma config STVREN = ON #pragma config LVP = OFF //#pragma config ICPRT = OFF #pragma config XINST = OFF // CONFIG5L #pragma config CP0 = OFF #pragma config CP1 = OFF #pragma config CP2 = OFF #pragma config CP3 = OFF // CONFIG5H #pragma config CPB = OFF #pragma config CPD = OFF // CONFIG6L #pragma config WRT0 = OFF #pragma config WRT1 = OFF #pragma config WRT2 = OFF #pragma config WRT3 = OFF // CONFIG6H #pragma config WRTC = OFF #pragma config WRTB = OFF #pragma config WRTD = OFF #pragma config EBTR0 = OFF #pragma config EBTR1 = OFF #pragma config EBTR2 = OFF #pragma config EBTR3 = OFF // CONFIG7H #pragma config EBTRB = OFF #define _XTAL_FREQ 4000000 volatile int ContRx,ContTx,RxFlag, C; volatile char x; volatile char bufferRx[60]; volatile char dum; char ce=48; char bufferTx[60]; char aux[60]; char conv[3]; int val,sensor=0; void interrupt high_priority Receive(void) { if(RCSTAbits.OERR) { RCSTAbits.CREN = 0; RCSTAbits.CREN = 1; PORTCbits.RC7= 0; } x = RCREG; if(x == 13) { bufferRx[ContRx] = x; bufferTx[ContRx] = bufferRx[ContRx]; RxFlag = 1; } else { bufferRx[ContRx] = x; bufferTx[ContRx] = bufferRx[ContRx]; } ContRx++; } int adc() { ADON = 1; __delay_ms(1); GO_nDONE = 1; while(GO_nDONE); val = (ADRESH<<8)+ADRESL; return(val); } void main(void) { //CONFIGURACIONES //OSCILLATOR OSCCONbits.IRCF= 0b111; OSCCONbits.SCS=0b10; //PORTS TRISA=1; PORTB = 0; TRISB=1; TRISC=0b10000000; //INTERRUPTIONS INTCONbits.GIE = 1; INTCONbits.PEIE = 1; RCONbits.IPEN = 1; // interrupt priority mode enabled, H or L interrupts INTCONbits.GIE_GIEH = 1; // high priority interrupts are enabled INTCONbits.PEIE_GIEL = 0; // low priority interrupts are enabled ADCON0bits.CHS = 12; ADCON1 = 0x00; ADCON2bits.ADCS = 0b000; ADCON2bits.ACQT = 0b111; ADCON2bits.ADFM = 1; PIE1bits.RC1IE = 1; //receive interrupt enabled PIE1bits.TX1IE = 0; //transmit interrupt disabled IPR1bits.RC1IP = 1; // receive is high priority PIR1bits.RCIF = 0; //RCSTA TXSTA RCSTAbits.SPEN=1; RCSTAbits.RX9=0; RCSTAbits.CREN=1; TXSTAbits.BRGH=0; TXSTAbits.SYNC=0; TXSTAbits.TXEN = 1; TXSTAbits.TX9=0; //BAUDRATE BAUDCON BAUDCONbits.ABDEN = 0; BAUDCONbits.WUE = 0; BAUDCONbits.TXCKP = 0; BAUDCONbits.RXCKP = 0; BAUDCONbits.BRG16=0; SPBRG=51; //51= 2400 12=9600 ContRx=0; ContTx=0; PORTBbits.RB7 = 1; while(1) { ContTx=0; while(RxFlag == 1) { for(sensor=1; sensor<12;sensor++) { val = adc(); __delay_ms(2); sprintf(conv,"%5d",val); sprintf(aux, "%s%s",aux,conv); aux[60] = 0x0A; val = 0; } sprintf(aux, "%s$rn",aux); for(int z=0;z<60;z++) { TXREG =aux[z]; while(TXSTAbits.TRMT==0); { aux[z] = 0x00; } } ContRx=0; RxFlag=0; } } } Attached Image(s) |
|
相关推荐
11个回答
|
|
你不需要这个:你有低优先级的UART TX中断设置,并且启用,但是你没有列出低优先级的IrrPut-ISR?
以上来自于百度翻译 以下为原文 You don't need/want this: #include You have the USART tx interrupt set for low priority and enabled yet you list no low priority interrput ISR? |
|
|
|
嗨,发送中断是不允许的。PY1BITS。TX1IE=0;评论是错误的。
以上来自于百度翻译 以下为原文 Hi, the transmit interrupt is disabled. PIE1bits.TX1IE = 0; the comment is wrong. |
|
|
|
我缩进了您的发布代码(实际上让MPLAB X在编辑器中执行),这就是结果。我不确定这是你期望的。如果这是因为复制/粘贴错误,那么可能重新发布正确的代码?
以上来自于百度翻译 以下为原文 while(1) { ContTx=0; while(RxFlag == 1) { for(ContTx=0; ContTx TXREG = bufferTx[ContTx]; while(TXSTAbits.TRMT==0); { // MY COMMENT HERE --- this part IS NOT part of the preceding while() statement due to the ; at the end of the above line bufferTx[ContTx]= 0x00; bufferRx[ContTx]= 0x00; } } ContRx=0; RxFlag=0; } } I indented your posted code (actually let MPLAB X do it in the editor) and this is the result. I am not sure this is doing what you expect it to. IF this is because of a copy/paste error then maybe re-post the correct code? |
|
|
|
谢谢,你说的是真的,这不是一段时间,这是我的错误,但那部分是按照预期的方式工作的。我得到的错误是,在接收到第九次字符“r”之后,代码暂停并没有响应。你可以在附件中看到这个。
以上来自于百度翻译 以下为原文 Thanks, It´s true what you point, its not part of the while and it was my mistake, but that part works as it is expected to. The error that I get is that after receiving for the 9th time the character 'r' the code pauses and does not respond. You can see this on the attached picture. |
|
|
|
我猜:由于某种原因,你已经超过了缓冲区。您发布的代码将无法工作,还有什么问题吗??
以上来自于百度翻译 以下为原文 My guess: you are over-running your buffers for some reason. Your code as posted will not work so there is something more?? |
|
|
|
好,我编辑了张贴的代码,这是有效的。关于过度运行,我如何知道这是问题,我能做些什么来解决这个问题?
以上来自于百度翻译 以下为原文 OK, I edited the posted code, this works. About the over-running, how can I know if this is the issue and what can I do to solve this? |
|
|
|
首先,在ISR中增加Currx,检查它是否达到缓冲区的大小。如果需要的话,你需要敲响警钟并停止一切。
以上来自于百度翻译 以下为原文 For starters, where you increment ContRx in the ISR, check that it never reaches the size of your buffer. You need to ring alarm bells and stop everything if it ever does. |
|
|
|
首先,在ISR中增加Currx,检查它是否到达缓冲区的大小。如果需要的话,你需要敲响闹钟并停止所有的事情。它永远不会达到传输后重新设置的缓冲区的大小。不管它是否发送1或错误,都会出现错误。60字
以上来自于百度翻译 以下为原文 For starters, where you increment ContRx in the ISR, check that it never reaches the size of your buffer. You need to ring alarm bells and stop everything if it ever does. it never reaches the size of the buffer it is reseted after the transmission ContRx=0; the error presents no matter if It´ll transmit 1 or 60 characters |
|
|
|
好,我编辑了张贴的代码,这是有效的。关于过度运行,我如何知道这是问题,我能做些什么来解决这个问题?只是对未来的帖子有一点建议:最好重新发布一个列表,但不要编辑原始文章,因为这真的让那些从一开始就没有跟上线程的人很难,他们真的需要看到原始的(即使不正确的)帖子来理解一些后来的帖子。是的,检查它在哪里递增索引。也可能需要一个循环缓冲器,这样做(如果做得正确)可以防止过度运行(您仍然可以丢失数据,但不会进入非预期内存区域)。如果您当前的方法由于任何原因错过了R(0x0d)字符,那么您将开始使用更多的缓冲区。
以上来自于百度翻译 以下为原文 OK, I edited the posted code, this works. About the over-running, how can I know if this is the issue and what can I do to solve this? Just a bit of advice for future posts: it is best to re-post a listing but NOT to edit the original post as this really makes it difficult for anyone who did not follow the thread from the very beginning, they really need to see the original (even if incorrect) post to understand some of the later comments/posts. Yes, check for it where you increment the index. Also maybe impliment a circular buffer, this (if done properly) will prevent the over-run (you can still lose data but not go off into unintended memory areas). If your present approach misses the r (0x0D) character for any reason then you will start using more buffer then you expect. |
|
|
|
好,我编辑了张贴的代码,这是有效的。关于过度运行,我如何知道这是问题,我能做些什么来解决这个问题?只是对未来的帖子有一点建议:最好重新发布一个列表,但不要编辑原始文章,因为这真的让那些从一开始就没有跟上线程的人很难,他们真的需要看到原始的(即使不正确的)帖子来理解一些后来的帖子。是的,检查它在哪里递增索引。也可能需要一个循环缓冲器,这样做(如果做得正确)可以防止过度运行(您仍然可以丢失数据,但不会进入非预期内存区域)。如果你现在的方法由于任何原因错过了R(0x0d)字符,那么你将开始使用更多的缓冲区,然后你期待。谢谢你的建议,我不会编辑原来的职位。好的,我将实现循环缓冲区,然后我将发布结果。
以上来自于百度翻译 以下为原文 OK, I edited the posted code, this works. About the over-running, how can I know if this is the issue and what can I do to solve this? Just a bit of advice for future posts: it is best to re-post a listing but NOT to edit the original post as this really makes it difficult for anyone who did not follow the thread from the very beginning, they really need to see the original (even if incorrect) post to understand some of the later comments/posts. Yes, check for it where you increment the index. Also maybe impliment a circular buffer, this (if done properly) will prevent the over-run (you can still lose data but not go off into unintended memory areas). If your present approach misses the r (0x0D) character for any reason then you will start using more buffer then you expect. Thanks for the advice, I won´t edit the original post. OK I´ll implement the circular buffer, then I´ll post the outcome. |
|
|
|
首先,在ISR中增加Currx,检查它是否到达缓冲区的大小。如果需要的话,你需要敲响闹钟并停止所有的事情。它永远不会达到传输后重新设置的缓冲区的大小。不管它是否发送1或错误,都会出现错误。60个字符,这只是一般的安全编程实践。您的现有代码假定发送者永远不会发送超过60个字符而没有CR,并且您将永远不会错过CR字符。如果您这样做,指针将超出缓冲区,并对您的其他变量造成严重破坏。为了你自己的利益,去发现它是否真的发生过。
以上来自于百度翻译 以下为原文 For starters, where you increment ContRx in the ISR, check that it never reaches the size of your buffer. You need to ring alarm bells and stop everything if it ever does. it never reaches the size of the buffer it is reseted after the transmission ContRx=0; the error presents no matter if It´ll transmit 1 or 60 characters This is just general safe programming practices. Your existing code assumes the sender will never transmit more than 60 characters without a CR, and that you will never miss a CR character. If you do, your pointer will go outside your buffer, and wreak havoc on your other variables. It's in your own self interest to find out if it ever does happen. |
|
|
|
只有小组成员才能发言,加入小组>>
5192 浏览 9 评论
2012 浏览 8 评论
1936 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3183 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2238 浏览 5 评论
746浏览 1评论
633浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
518浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
644浏览 0评论
544浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-1 14:35 , Processed in 1.572768 second(s), Total 99, Slave 82 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号