Just using the Basic Example AnalogReadSerial
.
// the setup routine runs once when you press reset:
void setup()
{
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop()
{
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}
I have a basic voltage divider set up between two 10K resistors from 5V to GND. I have verified with a DMM that the DC voltage at pin A0 is 2.5V. Grounding the A0 pin has no effect.
It also seems that enabling either ADC channel 7 (Arduino pin AD0) or enabling every channel, putting the ADC in free-running mode, and deliberately setting it to not sleep has no effect:
ADC->ADC_CHDR = 0;
ADC->ADC_CHER |= 0xFF;
ADC->ADC_MR |= 0b10000000;
ADC->ADC_MR &= 0b11011111;
Also, by running the sketch DigitalInputPullup
, I can get the LED on pin 13 to toggle and serial communication to work as I tie the pin to ground, demonstrating that the board is being programmed properly.
I guess I'm just stumped. Should be the simplest thing in the world and it's just not working.
EDIT: This is my attempt at manually controlling the ADC:
volatile unsigned long value;
void setup()
{
//ADC setup
ADC->ADC_WPMR &= 0xFFFE; //disable write protect
ADC->ADC_CHER = 0b100; //Enable AD2 |
ADC->ADC_MR &= 0b11111111000000001111111100000000;
ADC->ADC_MR |= 0b00000000000100100000000000000000; //software trigger, hi res, no sleep, not free running
ADC->ADC_IER = 0b100; //enable interrupt
ADC->ADC_IMR = 0b100; //enable interrupt in mask
ADC->ADC_CR |= 0b10; //start first conversion
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop()
{
ADC->ADC_CR |= 0b10; //start conversion
while (!(ADC->ADC_ISR & 0b100)); //wait for conversion to end
for (int i = 0; i <= 15; i++)
{
value = ADC->ADC_CDR[i]; //read conversion data for all channels
Serial.println(value);
}
Serial.println();
Serial.println();
Serial.println();
delay(3000);
}
Just doesn't seem to be doing anything. ADC_CHSR
(the ADC channel status register) shows channel 2 and only channel 2 enabled and conversions are starting and completing, yet now the conversion data is always 2048. Here's the serial output of all 15 channels, now in 12 bit mode:
0
0
4095
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4095
0
0
0
0
0
0
0
0
0
0
0
0
0