小学生
最后登录1970-1-1
在线时间 小时
注册时间2014-5-16
|
根据火哥的例程,重写了fputc函数,发送4096个浮点数到串口,定时器中断100ms发送一次,程序如下:
void TIM2_IRQHandler(void)
{
if ( TIM_GetITStatus(TIM2 , TIM_IT_Update) != RESET )
{
test = ADC_Value;
ADC_Value_16[0] = test >> 16;
test = ADC_Value;
test = test << 16;
test = test >> 16;
ADC_Value_16[1] = test;
ADC1_ConvertedValue[counter] = (float)ADC_Value_16[0] / 4096 * 3.3;
ADC2_ConvertedValue[counter] = (float)ADC_Value_16[1] / 4096 * 3.3;
//ADC1_ConvertedValue[counter] = 3.56;
//ADC2_ConvertedValue[counter] = 3.57;
printf("%f \r\n", ADC1_ConvertedValue[counter]);
printf("%f \r\n", ADC2_ConvertedValue[counter]);
counter++;
TIM_ClearITPendingBit(TIM2 , TIM_FLAG_Update);
}
}
串口调试助手接收到的数据大部分是正确,但是会无规律的出现一些错误值:
1.130347
1.222192
1.157739
1.224609
1.136792
1.223804
1.158545
1.223804
-2.000000
26815622248375008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
1.148877
1.218970
1.177075
1.218164
0.000000
26815622248375008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
1.190771
1.229443
1.237500
1.227026
1.252808
1.226221
正确的值应该是一个大于1的小数,其中0.000000 、26815622248375008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000、 -2.000000 都是错误值。
火哥的书上说在使用重定义printf函数时会因为缓冲区的大小而出现莫名其妙的错误,请教是这个原因导致的吗?如果是,要如何避免这种问题?
已经卡在这里很多天,实在没办法了。
|
|