开发平台:MDK
开发板:正点原子STM32精英板
实现功能:ADC的使用,通过串口打印出ADC采集的值,并转换成电压值,手动转动开发板的电位器调整,实现电压值0-3.3V显示。
1.先上原理图,使用的是哪个ADC口和通道:
利用跳帽把24脚连接在一起,也就是RV1和PA1 STM ADC连接起来。
2、ADC的框图:
3、ADC时序:
4、ADC寄存器:
5、ADC转换并通过串口打印出图:
6、代码:
while中把ADC读的值给到ADCX
adcx = adc_get_result_average(ADC_ADCX_CHY, 10)
temp = (float)adcx * (3.3 / 4096)
LED0_TOGGLE()
delay_ms(100)
printf(" ADC1_CH1_VOL: %.4f\r\n",temp)
ADC初始
g_adc_handle.Instance = ADC_ADCX;
g_adc_handle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
g_adc_handle.Init.ScanConvMode = ADC_SCAN_DISABLE;
g_adc_handle.Init.ContinuousConvMode = DISABLE;
g_adc_handle.Init.NbrOfConversion = 1;
g_adc_handle.Init.DiscontinuousConvMode = DISABLE;
g_adc_handle.Init.NbrOfDiscConversion = 0;
g_adc_handle.Init.ExternalTrigConv = ADC_SOFTWARE_START;
HAL_ADC_Init(&g_adc_handle);
HAL_ADCEx_Calibration_Start(&g_adc_handle);
ADC转换
adc_channel_set(&g_adc_handle , ch, ADC_REGULAR_RANK_1, ADC_SAMPLETIME_239CYCLES_5);
HAL_ADC_Start(&g_adc_handle);
HAL_ADC_PollForConversion(&g_adc_handle, 10);
return (uint16_t)HAL_ADC_GetValue(&g_adc_handle);
7、视频:
f3d6ad19319e6966a353a24c254f0b15
|