使用STM32F4点HAL库做ADC功能,开发板例子(ADC实验)里面只有单次采集的,我想做成连续采集,但是一直没成功.求指导.
下面是部分代码:
void MY_ADC_Init(void)
{
ADC1_Handler.Instance = ADC1;
ADC1_Handler.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
ADC1_Handler.Init.Resolution = ADC_RESOLUTION_12B;
ADC1_Handler.Init.ScanConvMode = ENABLE;
ADC1_Handler.Init.ContinuousConvMode = ENABLE;
ADC1_Handler.Init.DiscontinuousConvMode = DISABLE;
ADC1_Handler.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
ADC1_Handler.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
ADC1_Handler.Init.DataAlign = ADC_DATAALIGN_RIGHT;
ADC1_Handler.Init.NbrOfConversion = 1;
ADC1_Handler.Init.DMAContinuousRequests = DISABLE;
ADC1_Handler.Init.EOCSelection = ADC_EOC_SEQ_CONV;//ADC_EOC_SINGLE_CONV;
HAL_ADC_Init(&ADC1_Handler);
}
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
ADC_ChannelConfTypeDef ADC1_ChanConf;
GPIO_InitTypeDef GPIO_Initure;
if(hadc->Instance==ADC1)
{
__HAL_RCC_ADC1_CLK_ENABLE(); //使能ADC1时钟
__HAL_RCC_GPIOA_CLK_ENABLE(); //开启GPIOA时钟
GPIO_Initure.Pin=GPIO_PIN_5; //PA5
GPIO_Initure.Mode=GPIO_MODE_ANALOG; //模拟
GPIO_Initure.Pull=GPIO_NOPULL; //不带上下拉
HAL_GPIO_Init(GPIOA,&GPIO_Initure);
ADC1_ChanConf.Channel=ADC_CHANNEL_5; //通道
ADC1_ChanConf.Rank=1; //第1个序列,序列1
ADC1_ChanConf.SamplingTime=ADC_SAMPLETIME_480CYCLES; //采样时间
HAL_ADC_ConfigChannel(&ADC1_Handler,&ADC1_ChanConf); //通道配置
/* Peripheral interrupt init */
HAL_NVIC_SetPriority(ADC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(ADC_IRQn);
HAL_ADC_Start_IT(&ADC1_Handler); //开启ADC
//HAL_ADC_PollForConversion(&ADC1_Handler,10); //轮询转换
}
}
void ADC_IRQHandler(void)
{
HAL_ADC_IRQHandler(&ADC1_Handler);
}
u16 Get_Adc(u32 ch)
{
return (u16)HAL_ADC_GetValue(&ADC1_Handler); //返回最近一次ADC1规则组的转换结果
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>