如果快速发送数据,PIC18F 会锁定

发布于 2024-10-02 07:04:07 字数 503 浏览 4 评论 0原文

我正在使用 PIC18F,并尝试通过超级终端发送数据。当我每半秒按一个键以慢速发送数据时,它会收到数据并正确回显,但当我开始以更快的速率按下按键时,MCU 会锁定。不确定是什么原因造成的。

while(index<length){
    while(PIR1bits.RCIF==0); // Wait till char recieved
    sendData(str2,9); // confirm reception

    Delay1KTCYx(5); //delay because without it, it messes up.
    rxData[index]= RCREG; //char array
    index++;
}

PIC 和超级终端上的波特率均为 2400。

这是我们的接收循环。 sendData 只是我们发送“已收到”的调试代码。这就是我们如何知道它何时结冰的方式。

它不会每次都冻结相同数量的循环,这仅取决于我们输入数据的速度。

I'm working with a PIC18F and am trying to send data via hyperterminal. When I send data at a slow rate by pressing one key every half secondish it recieves the data and echos it correctly but when I start pressing the keys at a faster rate the MCU locks up. Not sure what causes this.

while(index<length){
    while(PIR1bits.RCIF==0); // Wait till char recieved
    sendData(str2,9); // confirm reception

    Delay1KTCYx(5); //delay because without it, it messes up.
    rxData[index]= RCREG; //char array
    index++;
}

baudrate is 2400 On both PIC and hyperterminal.

This is our receive loop. sendData is just debug code that we send saying "recieved". It's how we know when it has frozen.

It does not freeze at the same amount of loops everytime, it is solely on how fast we input data.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

巷雨优美回忆 2024-10-09 07:04:07

(我确实在 MCU 上工作,但没有处理 PIC,所以我会尽力帮助解决常见问题)

  1. 您不检查任何接收器错误标志。接收器可能会锁定在溢出错误状态,并且无法进一步接收,直到您清除溢出标志。添加错误条件检查并根据 PIC 文档解决它们。

  2. 好的做法是在指示接收完成时尽早读取接收到的字节,因此尝试在 while(PIR1bits.RCIF= 后立即移动 rxData[index]= RCREG; =0);。这降低了可能性

  3. 您没有显示 sendData 的代码。可能会错过对 TX 就绪状态和错误条件的检查,因此它也可能会锁定。

  4. 毫无动机的拖延表明你已经在某个地方出错了。尝试删除它,然后调试代码。

  5. 您应该分别测试您的接收和传输。首先,检查发送器:尝试通过UART输出长行文本,但没有任何接收。 (比如说,编写“Hello world!”程序:))

  6. 单独检查接收器代码:从程序中删除传输,连接 LED(电压表、示波器,无论你有什么)以释放 GPIO 引脚,然后使其打开逻辑电平每次收到一个字节时都会执行此操作。是否只需要几个时钟周期就可以完成,它不应该干扰接收或锁定。

(I did work on MCUs but haven't a deal with PICs, so i'll try to help with common problems)

  1. You do not check any receiver error flags. Receiver may lock up in Overrun Error state and do not receive further, until you clear Overrun flag. Add check for error conditions and resolve them accordinly to PIC documentation.

  2. Good practice is to read received byte as early, as possible when receive complete is indicated, so try to move rxData[index]= RCREG; imediately after while(PIR1bits.RCIF==0);. This lowers possibility

  3. You didn't shown code for sendData. There may be missed checking for TX ready state and error conditions, so it may also lock up.

  4. Unmotivated delay indicates that you're already going wrong somewhere. Try to remove it and THEN debug code.

  5. You should test your receive and transmit separately. At first, check transmitter: try to output long line of text through UART without any receiving. (Say, write "Hello world!" program:))

  6. Check receiver code alone: remove transmission from program, connect LED (voltmeter, oscillosocope, whatever you have) to free GPIO pin, and then make it toggle logic level on it every time it receives a byte. Is it takes only several clock ticks to do, it should not intervene receiving or lockup.

谎言 2024-10-09 07:04:07

也许当你发送 2 个字符而它正忙于发送“已接收”时,其中一个字符会被丢弃,并且你永远不会达到你的长度

Maybe when you send 2 characters while it is busy sending the "received" one of them is discarded and you never reach your length?

深海夜未眠 2024-10-09 07:04:07

在大多数微控制器上,UART 接收器溢出将导致新接收的字节被丢弃并设置标志,但接收器将继续正常运行。在 PIC 上,接收器溢出将导致 UART 死机,直到 CREN 位被清除并重置为止。

On most microcontrollers, a UART receiver overrun will cause the newly-received byte to be discarded and a flag to be set, but the receiver will continue to operate normally. On the PIC, a receiver overrun will cause the UART to die until the CREN bit is cleared and re-set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文