嘿,我有我的 usart 设置来从键盘读取中断并使用我的图片从我的面包板传输 ADC 读数。中断是用户可以输入的键盘命令,它将改变我模拟的面包板温度传感器的上限和下限。
我的问题有时是我的 usart 只是随机崩溃。它冻结并停止传输。当我输入键盘输入时会发生这种情况,甚至有时它正在传输句子中间的东西(比如 printf 的中途)然后我按 enter 并且中断似乎使 usart 崩溃,从而产生如下图所示的图像.
http://imageshack.us/photo/my-images/5/ftfk.png/
看一下突出显示的行,即我按下 Enter 的位置,以输出我通过缓冲区收集的字符流,它似乎刚刚将该输出减半并且也跳过了中断输出。
这里可能是什么问题,我应该寻找什么?
请在下面找到代码示例
void mainNema( char *nemaSentence) //this function processes my output and prints it out
{
int i;
for (i = 0; i< 20; i++) {
GPGGA_Tokens[i] = '\0';
}
parseNemaSentence(nemaSentence);
i = 0;
while (strcmp(GPGGA_Tokens[i], msgEndOfSentence)!=0) {
printf("\r\ntoken %i: %s\r\n",i, GPGGA_Tokens[i]);
i++;
}
evaluateTokens();
changeNema(token1,token2,token3);
if (token2 == 1)
printf("your new upper limit for channel %i is %i", token1, token3);
else
printf("your new lower limit for channel %i is %i", token1, token3);
}
下面是从 ADC 转换器读取并通过 usart 向用户打印“读数”的函数片段
ConvertADC(); //take value from potentiometer
while(BusyADC() == TRUE)
Delay1TCY();//wait until value is received
sampledValue = ReadADC(); //store value as sampledValue
setCurrentTemperatureForChannel(channelsel, sampledValue); //call function with channelsel and sampledValue
readSwitches(channelsel); //read inputs from pushbuttons
printf ("\n\rcurrent Temp of channel %i is %#x, highlimit is %i, low limit is %i \n\r", (channelsel+1), getCurrentTemperatureForChannel(channelsel),
getUpperLimitForChannel(channelsel),getLowerLimitForChannel(channelsel));