完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我使用PIC16F18345(作为MPLAB XPress DeV板的一部分),我试图让它读取串行端口上的多个字节。我从开发人员站点的简单单字节读取开始(http://MyChIPDeavest.ts:MCU11-SPARCTIONET12),它工作得很好。现在,我修改代码来尝试读取多个字节:当我运行这个命令时,不管我发送多少字符,内部while循环只运行一次(即,EUSARTXCOUNT变量总是0或1),它只读取一个字符。例如,如果我在串行上发送“ASD”,它将打印“最终字符串:A”。其他细节:-我使用MCC生成代码(见附上的PIC与EUSAT设置)-我已经尝试使用“虽然(EuStuthDATAARADY)”在内环中,我已经在论坛上看到了其他人的工作。当我这样做时,内部while循环永远不会运行。-启用外围和全局中断-使用MCCV3,编译器:XC8(V1.45),任何建议将不胜感激!
以上来自于百度翻译 以下为原文 Hello all, I am using PIC16F18345 (as part of the MPLAB Xpress dev board) and I am trying to get it to read multiple bytes on the Serial port. I started with the simple single-byte read from the Developer site (http://microchipdeveloper...ts:mcu1101-project-12) and it works fine. Now I modify the code to try and read multiple bytes: char readdata[10]; int i=0; int cmdRead=0; while (1) { while (eusartRxCount!=0) { // also tried while (EUSART_DataReady) readdata = EUSART_Read(); i++; cmdRead = 1; } if(cmdRead){ printf("FINAL STRING: %s n",readdata); cmdRead = 0; // reset i=0; } } When I run this, no matter how many characters I send, the inner while loop only runs once (i.e. the eusartRxCount variable is always either 0 or 1) and it only reads one character. For example, if I send "asd" on the serial, it will print "FINAL STRING: a". Other details: - I am using MCC-generated code (see attached pic with EUSART settings) - I have tried using "while (EUSART_DataReady)" in the inner loop which I have seen work for others on the forum. When I do this, the inner while loop never runs at all. - Peripheral and global interrupts are enabled - Using MCCv3, compiler: XC8(v1.45) Any advice would be appreciated! Attachment(s) MyConfig.txt (235.51 KB) - downloaded 50 times |
|
相关推荐
1个回答
|
|
您的阅读比UART传输快得多。要么你必须知道有多少个字符来,要么你需要一些指示(称为“定界符”)来决定何时停止对RX缓冲区的轮询和返回到外环。
以上来自于百度翻译 以下为原文 Your read is much faster than the UART transmission. Either you have to know how many characters are to come, or you'll need some indication (called "delimiter") to decide when to stop polling the RX buffer and returning to theouter loop. And there are many more concepts ... |
|
|
|
只有小组成员才能发言,加入小组>>
5170 浏览 9 评论
2001 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3176 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
737浏览 1评论
620浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
509浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
635浏览 0评论
531浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 15:07 , Processed in 1.272395 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号