cancel
Showing results for 
Search instead for 
Did you mean: 

stm8s003k3 multiple ADC channel reading error

KRiaz.1
Associate II

Hi everyone.

I am having problem reading data on ADC pins in stm8s003k3. I have attached three NTC at Ain1/2/3(which I suppose is also known as a channel) according to the datasheet. Problem is that when I put different channels in my code it shows one reading on two displays while the third display shows a random value. Here is my code. Kindly someone guide me or a bit of a hint. Thanks

void ADC_Init (unsigned char Channel)

{

CLK->PCKENR2 |= CLK_PCKENR2_ADC;

ADC1->TDRL = Channel;

ADC1->CR1 = ADC1_PRESSEL_FCPU_D18;

ADC1->CR2 = ADC1_ALIGN_RIGHT;

ADC1->CR1 |= ADC1_CR1_ADON;

}

unsigned int ADC_Read (unsigned char Channel)

{

unsigned int Result;

ADC1->CSR = Channel;

ADC1->CR1 |= ADC1_CR1_ADON;

ADC1->CR1 |= ADC1_CR1_ADON;

while (!(ADC1->CSR & ADC1_CSR_EOC));

Result = ADC1->DRL;

Result |= ADC1->DRH << 8;

return Result;

}

1 REPLY 1

With informations you provide one cant say more then... Probably because you are converting wrong channel. No schematic, no measured values, no complete code, no output values, no photo... i have to look for crystal ball. But one thing - why do you start conversion twice ?