I am using a simple code to read from ADC pin A0. When I read from ADCH and ADCL. The result is correct only once in the startup. When I change the analog value in A0, output from the ADC don't change at all. Unless I have reset the mcu.
In the datasheet it is not state clearly that there is a register called ADC. They highlight ADCH and ADCL.
reading from register ADC work fine.
This is my simple code that don't work.
/* * Section: Function Defintion */ void ADC_Setup(){ // Enable the ADC ADCSRA |= 1<<ADEN; // Select the refence voltage to be AVcc, which is connected to Vcc in the Arduino Nano board ADMUX |= 1<<REFS0; // Set Prescaler to 128, so that the ADC clock is 16M/128= 125Khz ADCSRA |= (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); ADCSRA |= (1<<ADSC) | (1<<ADATE) | (1<<ADIF) | (1<<ADIF); sei(); } void ADC_StartConvert(){ ADCSRA |= (1<<ADSC); } uint16_t ADC_read(){ uint16_t i = ADCH*256 + ADCL; // if changed to i = ADC; it work fine!! return i; } What is could be the cause to make the ADC hold conversion because of reading from ADCL?
uint16_t i = (uint16_t) (ADCL + (ADCH*256));becouse ADCL must be read first, then ADCH \$\endgroup\$