I've stripped everything that I'm sure is not relevant out of my code below. Basically we're inputting a signal through pin A0 and sending samples over serial. It's a relatively simple project but because we want to maximize speed we're trying to avoid using analogRead(). However instead of getting a curve back we get a flatline that doesn't respond to any input, only to the prescaler values.
I've verified all of the register changes and they are all set correctly. If we run the system with the analogRead() code then it works so I know the circuit is working. I can not find any clear information around about why this might be happening. I've played around with the ADMUX channel select to see if maybe I was on the wrong channel but I'm not. Overall I'm very confused by this right now!
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
void setup() {
// Opens up the serial port with a baud of 115200
Serial.begin(115200, SERIAL_8E2);
pinMode(A0, INPUT);
digitalWrite(A0, HIGH);
// Enable ADC Completion Interrupt
sbi(ADCSRA,ADIE) ;
sei() ;
// Select the correct pin for the ADC
cbi(ADMUX,MUX3);
cbi(ADMUX,MUX2);
cbi(ADMUX,MUX1);
cbi(ADMUX,MUX0);
// Set the ADC to left adjust so that MSB is in low Byte
sbi(ADMUX,ADLAR) ;
sbi(ADCSRA,ADEN) ;
sbi(ADCSRA,ADSC) ;
}
void loop()
{
}
ISR(ADC_vect)
{
Serial.write(ADCH);
cbi(ADCSRA,ADIF);
sbi(ADCSRA,ADSC);
}