I'm working on a project that will essentially become an oscilloscope in the long run. I am following this guide. My code is uploaded here for more reference.
In my .ino file I have called functions to set up register such that I have a timer ISR called at a frequency of 100 KHz, and an ADC clock rate of 2 MHz. The ADC is also set so that the result is left shifted so ADCH contains an 8-bit result. In a separate .h file I have an ADC ISR that looks like this:
ISR(ADC_vect)
{
// Read 8-bit conversion result from ADCH.
uint8_t byte0 = ADCL;
uint8_t byte1 = ADCH;
data_byte = byte1;
flag = true;
}
The loop() function is the following:
void loop()
{
if (flag == true)
{
//Serial.println("ISR HIT");
Serial.println(data_byte);
flag = false;
}
}
So, when the ISR is called the flag is set to true, and in the loop() function I am notified with an "ISR HIT" printed on the serial monitor, this operation is successful.
However, I also have a volatile global variable in my .ino function called data_byte (also declared as an extern in the .h file) that I set byte1 to. When byte1 is printed to the serial monitor the result is:
255
255
255
Any ideas on why the value of ADCH is stuck at 255? My hardware is simply a light sensor connected to pin A0, 3.3 V, and GND.
data_byte
. Or maybe you do in a version of the program you didn't publish. If we cannot see the code, there is no point in trying to guess what could be wrong.