ADC

ADC校准

1
2
3
4
5
HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc); //先校准ADC
* @param hadc: This parameter can be
1 &hadc1
2 &hadc2
* @retval HAL status
  例子:
  HAL_ADCEx_Calibration_Start(&hadc1);
  

软件开启一次转换

1
2
3
4
5
6
7
8
9
10
uint16_t ADC_IN_1(void) //ADC采集程序
{
HAL_ADC_Start(&hadc1); //开始ADC采集
HAL_ADC_PollForConversion(&hadc1,500); //等待采集结束
if(HAL_IS_BIT_SET(HAL_ADC_GetState(&hadc1), HAL_ADC_STATE_REG_EOC)) //读取ADC完成标志位
{
return HAL_ADC_GetValue(&hadc1); //读出ADC数值
}
return 0;
}

DMA连续转换

1 开启ADC 连续转换模式(不然转换一次就关闭了)
2 循坏模式 半字数据
1
2
3
4
5
6
7
8
HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)

* @param hadc: ADC handle
* @param pData: The destination Buffer address.
* @param Length: The length of data to be transferred from ADC peripheral to memory.
* @retval None

DMA must be configured to transfer size: half word.
例子:
 HAL_ADC_Start_DMA(&hadc1, (uint32_t *) & a1, 1); 
 adc1   转入a1中  每次连续转换1个