I'm using the Arduino Uno Wifi Rev2 for a project and I'm trying to get the value from an analog input during an interrupt.
I've followed the datasheet here http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega4808-4809-Data-Sheet-DS40002173A.pdf, particularly pages 395 to 422.
I think I'm on the right track but I'm not sure how to know what ADC and channel is connected to what pins on the Arduino. I also do not know how to format the interrupt function...
currently I get an error:
Arduino: 1.8.10 (Linux), Board: "Arduino Uno WiFi Rev2, ATMEGA328"
In file included from /home/ryacu/.arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h:27:0,
from sketch/ADC.ino.cpp:1:
ADC:39:5: error: expected ')' before '' token
ISR(ADC0.INTFLAGS_vect) {
^
ADC:39:5: error: expected ')' before '' token
ADC:39:5: error: expected ')' before '' token
ISR(ADC0.INTFLAGS_vect) {
^
ADC:39:5: error: expected ')' before '' token
exit status 1
expected ')' before '*' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
My sketch is below:
unsigned int val;
void setup() {
// ADC Setup
ADC0.CTRLA &= B01111111; // Run in Standby: Off
ADC0.CTRLA &= B11111011; // Resolution Selection: Full 10-bit resolution
ADC0.CTRLA |= B00000010; // Free-Running: On
ADC0.CTRLA |= B00000001; // ADC Enable: On
ADC0.CTRLB &= B11111000; // Sample Accumulation Number Select: 0
ADC0.CTRLC |= B01000000; // Sample Capacitance Selection: Reduced size of sampling capacitance
ADC0.CTRLC &= B11011111;
ADC0.CTRLC |= B00010000; // Reference Selection: VDD
ADC0.CTRLC |= B00000111; // Prescaler: DIV256
ADC0.CTRLD &= B00011111; // Initialization Delay: DLY0
ADC0.CTRLD &= B11101111; // Automatic Sampling Delay Variation: ASVOFF
ADC0.MUXPOS &= B11100000; // ADC input pin 0
ADC0.COMMAND |= B00000001; // Start Conversion: On
ADC0.EVCTRL &= B11111110; // Start Event Input: Off
ADC0.INTCTRL &= B11111101; // Window Comparator Interrupt Enable: Off
ADC0.INTCTRL |= B00000001; // Result Ready Interrupt Enable: On
// Serial Setup
Serial.begin(9600);
}
void loop() {
// Print Most Recent Reading Every Second
delay(1000);
Serial.println(val);
}
ISR(ADC0.INTFLAGS_vect) {
// Interrupt Setup
ADC0.INTFLAGS |= B00000001; // Clear Flag
val = ADC0.RES & 0x03FF;
}
I'd appreciate any help with knowing what ADC is connected to the pins as well as how to format the interrupt function correctly.
Thanks