When i write a small code, to enable the internal AREF and check it with my DMM, it works:
void setup()
{
Serial.begin(9600);
analogReference(INTERNAL); // Interne ADC Referenz einschalte
analogRead(A5);
Serial.println(ADMUX, BIN);
}
The Value in ADMUX is 0b11000101 according to the serial Output, exactly what i expect.
But when i integrate this to my Code, the selection of the AnalogReference has no affect, means AREF is 5V from USB and the Value in ADMUX is 0b01000101 after reading A5.
void setup()
{
#if(EXTENDED_DEBUG)
bDebug = true;
#endif
SerialCom.begin(BAUDRATE);
SerialDebug.begin(BAUDRATE);
if(bDebug)
{
SerialDebug.println("HALLO WELT!");
}
Serial.println(ADMUX, BIN);
analogReference(INTERNAL); // ADC Referenz einschalten
Serial.println(ADMUX, BIN);
ADMUX = 0b11000000;
Serial.println(ADMUX, BIN);
analogRead(A5);
Serial.println(ADMUX, BIN);
......
The Serial Monitor sends me the Following:
HALLO WELT!
0
0
11000000
1000101
This shows me, that the Reference selection must be stored in a Global Variable by the Arduino Library Function and gets set in the same register modification with the analog channel selection, and my entry the ADMUX-Register gets owerwritten by analogRead.
How can i check what part of my code causes, that the Reference Selection is not properly stored?