stm32f030ADC单次单通道采样
作者:互联网
void adc1_dma_init(void) { ADC_InitTypeDef ADC_InitStruct; // DMA_InitTypeDef DMA_InitStruct; GPIO_InitTypeDef GPIO_InitStruct; ADC_DeInit(ADC1); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 , ENABLE); //RCC_ADCCLKConfig(RCC_ADCCLK_PCLK_Div4); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_1; //GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOA, &GPIO_InitStruct); ADC_DeInit(ADC1); ADC_DMACmd(ADC1, DISABLE); ADC_StructInit(&ADC_InitStruct); ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b; ADC_InitStruct.ADC_ContinuousConvMode = DISABLE; ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_TRGO; ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStruct.ADC_ScanDirection = ADC_ScanDirection_Backward; ADC_Init(ADC1, &ADC_InitStruct); ADC_ChannelConfig(ADC1, ADC_Channel_1, ADC_SampleTime_1_5Cycles); // ADC_ChannelConfig(ADC1, ADC_Channel_3, ADC_SampleTime_55_5Cycles); // ADC_ChannelConfig(ADC1, ADC_Channel_4, ADC_SampleTime_55_5Cycles); // ADC_ChannelConfig(ADC1, ADC_Channel_5, ADC_SampleTime_55_5Cycles); ADC_GetCalibrationFactor(ADC1); // ADC_DMACmd(ADC1, ENABLE); ADC_Cmd(ADC1, ENABLE); while(ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN)==RESET); ADC_StartOfConversion(ADC1); while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)==RESET); adc_data=ADC_GetConversionValue(ADC1); }
void adc_chanlset(uint32_t ADC_Channel) { ADC_ChannelConfig(ADC1,ADC_Channel,ADC_SampleTime_1_5Cycles); } int haveadval() { ADC_StartOfConversion(ADC1); while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)==RESET); adc_data=ADC_GetConversionValue(ADC1); return adc_data; }
标签:Pin,stm32f030ADC,InitStruct,ADC,ADC1,GPIO,RCC,单次,单通道 来源: https://www.cnblogs.com/logicexpression/p/15709467.html