完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
这与我在前一个帖子中发布的问题非常相似(显然,我无法链接这个线程而没有论坛软件在权限错误上产生异常),但是由于我对代码进行了一些修改,并且使用了稍微不同的处理数据的方式,所以i我现在应该使用一个单独的线程。对于上下文,我现在使用中断来接收我的数据,以我的芯片设置作为同步接收从,并且反复发送字符串“Word”,后面跟着A。我的发射机时钟在4MHz,KbAd值为9.615(SPBRG B的十进制值)。EN 103)。我使用的是两个PIC16F628 A,一个是发射机,另一个是接收机。这是我的接收代码:由于我收到的一些反馈,我学会了如何实现中断,并把数据的处理/写入到一个单独的函数中,并用一个缓冲器…然而,当我收到数据并阅读EEPROM时,我所得到的只是“Word Word Word Word Word”,而D是从来没有写过的。我已经确认了几次D确实是通过检查它来发送的,所以这不是我的发射机代码的问题。我怎样才能确保D确实被写入和处理正确?我得到的建议是,如果我知道数据的大小,我可以把它存储在一个通用缓冲器中,然后把它一次写入EEPROM,但是为了我项目的这一部分的生产目的,实际上,我收到的一个芯片的数据将是随机的,从8到15字节,没有null终止符,我必须正确处理和存储这个。这种随机的数据流每隔几秒钟就会发给我一次。这就让我回到了一个问题:我如何确保准确地处理数据而不丢失任何东西?
以上来自于百度翻译 以下为原文 So this is extremely similar to the issue I posted about here in my previous thread (and apparently I can't link the thread without the forum software freaking out over permission errors), but since I made some modifications to my code and am using a slightly different way of handling my data, I figured I should make a separate thread. For context, I am now using interrupts to receive my data with my chip setup as a Synchronous Recieve Slave and am repeatedly sending the string "World" followed by a __ms_delay(2000);. I have the transmitter clocked at 4Mhz with a KBAUD value of 9.615 (decimal value for SPBRG being 103). I am using two PIC16F628A's, one acting as a transmitter and the other a receiver. Here is my reciever code: volatile unsigned char addr = 0x00; void USART_init(void){ TRISBbits.TRISB1 = 1; TRISBbits.TRISB2 = 1; TXSTAbits.SYNC = 1; RCSTAbits.SPEN = 1; TXSTAbits.CSRC = 0; PIE1bits.RCIE = 1; INTCONbits.GIE = 1; INTCONbits.PEIE = 1; RCSTAbits.CREN = 1; } void writestuff(unsigned char x){ EEPROM_WRITE(addr, x); addr++; } void interrupt message(void){ if(PIR1bits.RCIF == 1){ unsigned char d = RCREG; writestuff(d); } } void main(void) { USART_init(); while(1){} } Because of some of the feedback I received, I learned how to implement interrupts and put the processing/write of data to the EEPROM in a separate function with a buffer... Yet still, when I receive the data and read the EEPROM, all I get is "WorlWorlWorlWorlWorl", the d is never written. I have confirmed several times that the d is indeed sent by checking for it specifically so it's not an issue with my transmitter code. How can I make sure the d is indeed written and processed correctly? I have gotten the recommendation that if I know the size of the data, I can just store it in a universal buffer and then write it all at once to EEPROM, but for production purposes of this section of my project, in reality, the data that I receive by a chip will be random in size, ranging from 8 to 15 bytes with no null terminator and I have to correctly process and store this. This random stream of data will be sent to me every couple of seconds or so. So that leads me back to the question of how I can make sure to accurately process the data without losing anything? |
|
相关推荐
19个回答
|
|
我不认为创建一个新线程有很大的意义,如果你总是引用以前的PothTtp://www. McCHIP.COM/FUMMS/M1038 435.ASPX
以上来自于百度翻译 以下为原文 I dont' think this does make much sense to create a new thread, if you always have to refer to your previous post http://www.microchip.com/forums/m1038435.aspx |
|
|
|
您实际上在ISR中执行EEPROM写入功能,可能不是一个好主意。您所示的代码没有“4字节限制”,所以它在EEPROMYWORTER()函数中,或者在您没有显示的代码中。可能EEPROMITWREST()需要花费太长时间吗?还是出错?为了测试,将接收到的数据回传到发射机,并监视它以查看接收到的数据。
以上来自于百度翻译 以下为原文 You are actually performing the eeprom write function within your ISR, possibly not a great idea. Your code as shown has no "4 byte limit" so either it is in the EEPROM_Write() function or in code you do not show. Possibly the EEPROM_Write() takes too long? Or hits an error? For testing, echo the received data back out the transmitter and monitor that to see what is received. |
|
|
|
如上所述,如果将EEPROM写入中断服务中,则不会增加任何中断。
以上来自于百度翻译 以下为原文 As above. You gained nothing by adding interrupts if you put the EEPROM write inside the interrupt service. |
|
|
|
我有一个简单的测试建议:选择一个未使用的端口引脚,将其设置为输出。当你从ISART读取一个字节时,在ISR中切换PIN。选择另一个未使用的端口PIN,使其成为输出。在EEPROM)写()函数调用之前设置PIN高,并在调用之后将其设置为低。检查两个输出之间的关系,看看是否重叠(EEPROFIX写得太长)。
以上来自于百度翻译 以下为原文 I have a simple testing suggestion: Pick an unused port pin, set it as an output. In your ISR toggle the pin when you read a byte from the USART. Pick another unused port pin, make it an output. Set the pin HIGH just before the EEPROM)WRITE() function call and set it LOW just after the call. Check the relationship of the two outputs to see if you are overlapping (EEPROM_WRITE takes too long). |
|
|
|
在9615波特时,8比特的字符需要小于1毫秒。EEPROM写入可以占用4毫秒。
以上来自于百度翻译 以下为原文 At 9615 baud, a character of 8 bits takes less than 1 ms. EEPROM write can take up to 4 ms. |
|
|
|
如果您正在向EEPROM写入字符串,则添加1以包含null终止符。CONST CHAR*G=“GORT1951”;FunFoc(g,StLLEN(G)+ 1);// 9字节Inulnulor使用长度为第一字节的Pascal字符串。8英镑& GTT1951
以上来自于百度翻译 以下为原文 If you are writing strings to the eeprom, add 1 to include the null terminator. const char *g="Gort1951"; somefunc(g,strlen(g)+1); //9 bytes inc. null Or use Pascal strings with the length as the first byte. <8>Gort1951 |
|
|
|
此外,EEPROMyWrreWrar()是否会等待写完成,所以我认为你有一个竞赛条件。
以上来自于百度翻译 以下为原文 |
|
|
|
指定:AyEpWrd::int EpWrand(Uint地址,const Vult*Src,int Len);EpScript(0,g,StLLEN(G)+ 1);写锁存缓冲器比字节写入快很多。
以上来自于百度翻译 以下为原文 Specify: _epwrite: ;int epwrite(uint Address, const void *Src, int Len); epwrite(0,g,strlen(g)+1); Writing latch buffers is a lot faster than byte writes. |
|
|
|
|
|
|
|
|
|
|
|
只是一个标准的原型。您将使用数据写入EEPROM。这是外部EEPROM/S。我已经失去了两个线程的跟踪。
以上来自于百度翻译 以下为原文 Just a standard proto. you would use to write data to an eeprom. That is external eeprom/s. I've lost track with two threads. |
|
|
|
校正,EEPROMYWREST()在写入之前检查写入完成;它是EEPROMYRADE(),它不等待写入完成。当接收到W时,它被写入EEPROM。由于需要4毫秒完成写,“ORL”同时被接收到双缓冲FIFO和RSR,并且字母“D”丢失。
以上来自于百度翻译 以下为原文 Correction, EEPROM_WRITE() checks for write complete before writing; it is EEPROM_READ() that does not wait for write to complete. When 'W' is received, it is written to the EEPROM. Since it takes ~4 ms to complete the write, "orl" are received in the meantime into the double-buffered FIFO and the RSR, and the letter 'd' is lost. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
只需检查一些PIC18F420 CODE.EEPROMYRADE和EEPROMETH写在该芯片上的小写,就可以将忙碌/等待建立在EEPROMIX写入函数中。
以上来自于百度翻译 以下为原文 Just checking through some old PIC18F4520 code. eeprom_read and eeprom_write in lowercase on that chip, the busy/wait is built into the eeprom_Write function. I would have thought it would be the same for EEPROM_WRITE on this chip. |
|
|
|
无需猜测.5.5.5.3 EEPROM访问功能和5.5.5.4 EEPROM访问MAXROIN XC8用户指南告诉您功能/宏版本的具体功能。
以上来自于百度翻译 以下为原文 No need to guess. 5.5.5.3 EEPROM ACCESS FUNCTIONS and 5.5.5.4 EEPROM ACCESS MACROS in the XC8 User Guide tell you exactly what the function/macro versions do. |
|
|
|
我也有点担心OP正在采取的基本方法——写在每个字符上的EEPROM上。我不确定这是否是内部EEPROM,在闪存或外部EEPROM中仿真EEPROM,但无论哪一种,它们对擦除/写入周期都有限制。是1000000(如许多外部EEPROM),那么您将在9600波特的连续接收的几天内耗尽单元。即使写入缓冲器,然后保存它也会更好。苏珊
以上来自于百度翻译 以下为原文 I'm also a bit concerned about the underlying approach the OP is taking - writing to EEPROM on each and every character. I'm not sure if this is an internal EEPROM, emulated EEPROM in FLASH or an external EEPROM but whichever, they have limits on the erase/write cycles they can maintain. Even if that is 1,000,000 (as many external EEPROMs are) then you will wear out the cells in a small number of days of continuous reception at 9600 BAUD. Even writing to a buffer and then saving that would be better. Susan |
|
|
|
我注意到,在离开ISR之前,您没有清除UART中断标志。这将不允许设置另一个中断标志。因此,您将无法再次从UART通道接收。将此语句放入ISR例程EPIR1BIT内的任何地方。RCIF=0;对于我来说,我将重写ISR代码:无符号char;空隙IpUTUTE(){if(pRI1BIT)。RCIF){D= RCREG;PIR1BIT。RCIF=0;}}无效主(){UART1IIN(9600);ITCON.GEE=1;PIE=1;PIR。RCIF=0;PIR。RCIE=1;d=0;而(1){if(d)!= 0){ReestSufff(d);/ /调用EEPROM写入函数,这里d=0;/ /清除变量}}
以上来自于百度翻译 以下为原文 I noticed that you did not clear the UART interrupt flag before leaving the ISR. this will not allow another interrupt flag to be set. Hence you will not be able to receive again from the uart channel. Put this statement anywhere within the isr routine PIR1bits. RCIF=0; For me I will rewrite the ISR code as: unsigned char d; void interupt(){ if(PIR1bits. RCIF) { d=RCREG; PIR1bits. RCIF=0; } } void main(){ Uart1_Init(9600); INTCON.GIE=1; INTCON. PEIE=1; PIR. RCIF=0; PIR. RCIE=1; d=0; while(1){ if(d!=0){ writestuff(d); //call your EEPROM Write function here d=0; //clear the variable } } } |
|
|
|
只有小组成员才能发言,加入小组>>
5183 浏览 9 评论
2005 浏览 8 评论
1932 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3178 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2229 浏览 5 评论
739浏览 1评论
626浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
510浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
637浏览 0评论
535浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-27 21:06 , Processed in 1.621689 second(s), Total 112, Slave 96 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号