Microchip
直播中

谢赛

7年用户 276经验值
私信 关注
[问答]

使用MCC的多字节读取EUSART内部while循环只运行一次

大家好,我使用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)

王璨

2018-11-2 15:14:55
您的阅读比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 ...
举报

更多回帖

发帖
×
20
完善资料,
赚取积分