在lab4.c中有以下两条重要语句
cdcReceiveDataInBuffer(dataBuffer, BUFFER_SIZE, CDC0_INTFNUM);//接收
cdcSendDataInBackground(dataBuffer, bytesReceived,CDC0_INTFNUM, 0);//发送
在文件开头声明了:
#define BUFFER_SIZE 40
uint8_t dataBuffer[BUFFER_SIZE]; // User buffer to hold the data
我想把采集到的数值,传到电脑上
于是尝试了以下做法:
1 采集到浮点数:
float temperatureDegC;
2 把采集到的浮点数转化成字符串
char tempstr[7]="1234567";
sprintf(tempstr,"%d.%d",(unsigned int)temperatureDegC,(unsigned int)((temperatureDegC-(unsigned int)temperatureDegC)*1000));
3 字符数组给dataBuffer赋值
for(i=0;i<7;i++)
{
dataBuffer[i]=tempstr[i];
}
4 把dataBuffer中的字发送出去
cdcSendDataInBackground(dataBuffer, 6,CDC0_INTFNUM, 0);