microcon555
Advanced Member level 4
Hi
I am using STM8S003K3 and trying to read adc value from channel 0.
Here is my try.
I am getting random values. Some one point out the error? or give me a good example.
I am using IAR compiler
MicroCon
I am using STM8S003K3 and trying to read adc value from channel 0.
Here is my try.
Code:
void SetupADC()
{
// ADC1_TRDL=1;
//ADC_CR1_ADON = 1; // Turn ADC on, note a second set is required to start the conversion.
ADC_CSR_CH = 0x00; // ADC on AIN4 only.
ADC_CR3_DBUF = 0;
ADC_CR2_ALIGN = 1; // Data is right aligned.
//ADC_CSR_EOCIE = 1; // Enable the interrupt after conversion completed.
ADC_CR1_CONT= 0;
ADC_CSR_AWD = 0;
}
void get_adc()
{
unsigned char low, high;
ADC_CR1_ADON = 1; // Turn ADC on, note a second set is required to start the conversion.
ADC_CR1_ADON = 1; // Turn ADC on, note a second set is required to start the conversion.
value1=0;
while(ADC_CSR_EOC== 0); // Wait till EOC
low = ADC_DRL; // Extract the ADC reading.
high = ADC_DRH;
value1 = (high*256)+low;
}
I am getting random values. Some one point out the error? or give me a good example.
I am using IAR compiler
MicroCon