问题描述
我尝试将 ADC 值放入一维数组并将其传输到 PC。 但它不工作。我使用 HAL_ADC_GetValue() 从 ADC1 的 chanel0 读取数据。 这是我的代码:
// maxziedata = 2048.
uint8_t DATA_ALL[MAXSIZEDATA];
void ReadAll(){
memset(DATA_ALL,sizeof(DATA_ALL));
delay_us(timeDelay);
int count =-1;
//Read 32 Row
for(int row=0; row<32; row++){
SelectRow(row); //Read 32 Row
for(int col=0; col<32; coL++){
SelectCol(col); //Read 32 Column
++count;
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1,50);
HAL_IS_BIT_SET(HAL_ADC_GetState(&hadc1),HAL_ADC_STATE_REG_EOC);
delay_us(10);
uint16_t data = HAL_ADC_GetValue(&hadc1); // Data is alway equal 0
// if data = n,PC will received data.
DATA_ALL[count*2] = data & 0xff;
DATA_ALL[count*2+1] = (data >> 8) & 0xff;
HAL_ADC_Stop(&hadc1);
}
HAL_GPIO_WritePin(GPIOB,EN_COL_1_Pin,GPIO_PIN_SET);
}
HAL_GPIO_WritePin(GPIOA,EN_ROW_1_Pin,GPIO_PIN_SET);
}
如果我伪造数据 uint16_t data = HAL_ADC_GetValue(&hadc1);
更改为 uint16_t data = count
,PC 将接收数据。
当我只发送一个数组值时,PC会收到数据。
void ReadOne(int row,int col){
memset(SEND_DATA,sizeof(SEND_DATA));
HAL_ADC_Start(&hadc1);
SelectRow(row);
SelectCol(col);
HAL_ADC_Start(&hadc1);
delay_us(100);
HAL_ADC_PollForConversion(&hadc1,1);
uint16_t avg = 0;
for(int i=0; i<samplingTimes; i++){
avg += HAL_ADC_GetValue(&hadc1);
}
SEND_DATA[(row*32+col)*2] = avg/samplingTimes & 0xff;
SEND_DATA[((row*32+col)*2)+1] = (avg/samplingTimes >> 8) & 0xff;
HAL_ADC_Stop(&hadc1);
delay_us(100);
}
这是我的配置 ADC:
主要问题是HAL_ADC_GetValue()循环步骤后无法将数据放入数组
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)