STM32CubeMXADC多通道数据采集+内部传感器温度(非DMA方式)
轮询多通道采集
uint32_t ADC_Value[6];
uint8_t i;
float ad0,ad1,ad2,ad3,ad4,temp;
for(i=0;i<6;i++)
{
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1,50);
ADC_Value[i]=HAL_ADC_GetValue(&hadc1);
}
HAL_ADC_Stop(&hadc1);
ad0 = (float)(ADC_Value[0]&0xFFF)*3.3/4096;
ad1 = (float)(ADC_Value[1]&0xFFF)*3.3/4096;
ad2 = (float)(ADC_Value[2]&0xFFF)*3.3/4096;
ad3 = (float)(ADC_Value[3]&0xFFF)*3.3/4096;
ad4 = (float)(ADC_Value[4]&0xFFF)*3.3/4096;
temp = (float)(ADC_Value[5]&0xFFF)*3.3/4096;
printf("ADC0:%1.4f\r\n",ad0);
printf("ADC1:%1.4f\r\n",ad1);
printf("ADC2:%1.4f\r\n",ad2);
printf("ADC3:%1.4f\r\n",ad3);
printf("ADC4:%1.4f\r\n",ad4);
printf("temp:%1.4f\r\n",temp);
HAL_Delay(1000);
printf("\r\n");
|