avr: atmega328p ADC always reads max value

Discussion in 'General' started by makiyoung, Jun 30, 2017.

  1. I've been trying to sample an analog signal with the atmega328p(here is the datesheet of atmega328p) in c. Previously i've got this working with something similar, but somehow this time i can't get it to work. I've tried to make a minimal example that gets me the same result:

    #include <avr/io.h>

    uint8_t data[2];

    ADMUX = (1 << REFS0);
    ADCSRA = (1 << ADEN);

    ADCSRA |= (1 << ADSC);
    while (ADCSRA & (1 << ADSC));
    data[1] = ADCL;
    data[0] = ADCH;
    This code results in the array data = {0b00000011, 0b11111111}, no matter what. As the atmega328p has a 10-bit adc, this is the maximum value, so i'm probably doing something wrong but i just can't spot the mistake.

    Thanks in advance for any answers

  2. Did you try adding more cowbell?


Share This Page