在线时间17 小时
UID3502359
ST金币42
蝴蝶豆0
注册时间2018-8-21
该用户从未签到
中级会员
- 最后登录
- 2018-9-20
|
楼主 |
发表于 2018-8-27 12:12:34
|
显示全部楼层
#include "stm32l4xx.h"
//#include "stm32l476g_discovery.h"
#include "adc.h"
#include "stm32l4xx_hal_adc.h"
ADC_HandleTypeDef hadc1;
DMA_HandleTypeDef hdma_adc1;
ADC_ChannelConfTypeDef sConfig;
void ADC1_conf(void)
{
HAL_Init(); // HAL Init
/**Configure the global features of the ADC (Clock, Resolution, Data,Alignment and number of conversion) */
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = ENABLE; //upward
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_SOFTWARE_START; //software trigger
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING; //rising edge
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; //< Data right alignment
hadc1.Init.NbrOfConversion = 2; /* This parameter must be a number between Min_Data = 1 and Max_Data = 16.
Note: This parameter must be modified when no conversion is on going on regular group (ADC disabled,
or ADC enabled without continuous mode or external trigger that could launch a conversion). */
hadc1.Init.DMAContinuousRequests = ENABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */
sConfig.Channel = ADC_CHANNEL_5;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_12CYCLES_5; // Sampling time 12.5 ADC clock cycles at ADC resolution 12 bits.
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */
sConfig.Channel = ADC_CHANNEL_3;
sConfig.Rank = 2;
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
} |
|