配置多通道ADC
配置定时器1s读一次
主函数中等待转换完成的标志位,然后打印出来。
uint16_t adc_buffer[2] = {0};
uint8_t adc_flag;
float curr,vol;HAL_ADCEx_Calibration_Start(&hadc);
HAL_TIM_Base_Start(&htim3);
HAL_ADC_Start_DMA(&hadc,(uint32_t *)&adc_buffer,2);
while(1)
{if(adc_flag==1){vol=vol*0.0006103515625*100;curr=curr*0.0006103515625*100;adc_flag=0;HAL_TIM_Base_Start(&htim3);HAL_ADC_Start_DMA(&hadc,(uint32_t *)&adc_buffer,2);}
}
ADC回调函数中将数值赋值给变量
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{HAL_TIM_Base_Stop(&htim3);HAL_ADC_Stop_DMA(hadc);adc_flag=1;curr=adc_buffer[0];vol=adc_buffer[1];
}