Skip to main content
Visitor II
June 18, 2022
Question

stm8s003k3 multiple ADC channel reading error

  • June 18, 2022
  • 1 reply
  • 964 views

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;

}

    This topic has been closed for replies.

    1 reply

    Graduate II
    June 19, 2022

    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 ?