Created
July 6, 2020 19:44
-
-
Save andrewsclapp/8ceb4ee34d24a00a37c85abd32fb242f to your computer and use it in GitHub Desktop.
Simple STM8L ADC Read
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned int ADC_Read (uint16_t Channel) { | |
uint16_t ADC_value = 0; | |
CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE); | |
ADC_Init(ADC1, ADC_ConversionMode_Single, ADC_Resolution_12Bit, ADC_Prescaler_1); | |
ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles); | |
ADC_Cmd(ADC1, ENABLE); | |
ADC_ChannelCmd(ADC1, Channel, ENABLE); | |
ADC_SoftwareStartConv(ADC1); | |
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET) { | |
} | |
ADC_value = ADC_GetConversionValue(ADC1); | |
return(ADC_value); | |
} | |
~ | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment