【stm32】hal库-双通道ADC采集
CubeMX图形化配置
程序编写
/* USER CODE BEGIN PV */
#define BATCH_DATA_LEN 1
uint32_t dmaDataBuffer[BATCH_DATA_LEN];
/* USER CODE END PV */
/* USER CODE BEGIN 2 */
lcd_init();
lcd_show_str(10, 10, 24, "Demo14_4:ADC1 + ADC2 Sync", RED);
lcd_show_str(10, 40, 24, "Triggered by TIM3 each 500ms", RED);
lcd_show_str(10, 70, 24, "Please set jumper at first", RED);
lcd_show_str(10,100, 24, "Tune potentiometer for input", RED);
lcd_show_str(10,130, 24, "ADC1 Vref(mV) = ", RED);
lcd_show_str(10,190, 24, "ADC2 In5(mV) = ", RED);
HAL_ADCEx_MultiModeStart_DMA(&hadc1, dmaDataBuffer, BATCH_DATA_LEN);
HAL_ADCEx_MultiModeStart_DMA(&hadc2, dmaDataBuffer, BATCH_DATA_LEN);
HAL_TIM_Base_Start(&htim3);
/* USER CODE END 2 */
/* USER CODE BEGIN 4 */
__weak void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
uint32_t Volt;
uint32_t adcValue = dmaDataBuffer[0];
uint32_t ADC1_val = adcValue & 0x0000FFFF;
Volt = 3300 * ADC1_val >> 12;
lcd_show_num(50, 160, Volt, 4, 24, RED);
uint32_t ADC2_val = adcValue & 0xFFFF0000;
ADC2_val = ADC2_val >> 16;
Volt = 3300 * ADC2_val >> 12;
lcd_show_num(50, 220, Volt, 4, 24, RED);
}
/* USER CODE END 4 */
修改adc.c中的此部分为ENABLE
实现效果
ADC1采集内部电压
ADC2采集外部输入电压