初级会员

- 积分
- 174
- 金钱
- 174
- 注册时间
- 2012-3-29
- 在线时间
- 18 小时
|
发表于 2017-5-24 16:55:23
|
显示全部楼层
以使用ADC1为例:
ADC_HandleTypeDef hadc1;
/* Step1:重写ADC中断回调函数 */
/*
* @ADC转换完成回调函数
*/
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* AdcHandle) {
unsigned short int u16Value;
if(AdcHandle->Instance == ADC1) {
u16Value = HAL_ADC_GetValue(AdcHandle);
// TODO
}
}
/* step2: 初始化ADC*/
MX_ADC1_Init();
/* step3: 启动一次中断模式采样 */
HAL_ADC_Start_IT(&hadc1);
说明:初始化函数中必须使能ADC中断
/* stm32f4xx_hal_msp.c */
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) {
GPIO_InitTypeDef GPIO_InitStruct;
if(hadc->Instance==ADC1) {
//...
/* Peripheral interrupt init */
HAL_NVIC_SetPriority(ADC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(ADC_IRQn);
}
}
|
|