Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewsclapp/8ceb4ee34d24a00a37c85abd32fb242f to your computer and use it in GitHub Desktop.
Save andrewsclapp/8ceb4ee34d24a00a37c85abd32fb242f to your computer and use it in GitHub Desktop.
Simple STM8L ADC Read
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