This code is from a sketch that I found in my eternal quest to solve SoftwareSerial. The complete sketch is quite lengthy and complex.
The variable OCR0A is only referenced here, nowhere else and it produces a compiler error
'OCR0A' was not declared in this scope.
It seems that I could just delete it with no consequence unless it is a reserved word from some library that I do not have.
What say you one and all ?
[void useInterrupt(boolean v)
{
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
[b]OCR0A [/b]= 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}
OCR0A is the Compare A register for Timer0. It is a chip register, just like TIMSK0, which you also write.
Regards,
Ray L.
hextejas:
This code is from a sketch that I found in my eternal quest to solve SoftwareSerial. The complete sketch is quite lengthy and complex.
The variable OCR0A is only referenced here, nowhere else and it produces a compiler error
'OCR0A' was not declared in this scope.
It seems that I could just delete it with no consequence unless it is a reserved word from some library that I do not have.
What say you one and all ?
void useInterrupt(boolean v)
{
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}
That function, when you give it an argument of TRUE, will set the timer 0 compare register A to 0xAF, then enable the timer compare interrupt. If the argument is FALSE, it disables the interrupt. Timer 0 is already used to generate an interrupt when the counter overflows, to drive the millis() counter, so you are adding an additional interrupt whenever the timer count reaches 0xAF, for whatever you wish to use it for (I've personally used it to drive the display scan for a 7-segment LED display).
It seems that I could just delete it with no consequence
No, it is critical for the intended function.
Then how do I get rid of this error ?
'OCR0A' was not declared in this scope ?
You will have to modify the sketch to run on whatever board you are using. That piece of code is made to run on an atmega328 or similar processor, and is directly accessing the hardware registers, which are processor specific. The code enables or disables an interrupt that occurs once every 1.024mS (assuming the timer0 settings have not been altered).
This code is from a sketch that I found in my eternal quest to solve SoftwareSerial.
Can you provide a link to the source of the sketch, and explain what exactly you are trying to "solve" about SoftwareSerial.
There are better software serial options that SoftwareSerial, discussed here.
david_2018:
You will have to modify the sketch to run on whatever board you are using. That piece of code is made to run on an atmega328 or similar processor, and is directly accessing the hardware registers, which are processor specific. The code enables or disables an interrupt that occurs once every 1.024mS (assuming the timer0 settings have not been altered).
Can you provide a link to the source of the sketch, and explain what exactly you are trying to "solve" about SoftwareSerial.
Thank you david that is a quite useful explanation..
By solve I meant to make it work properly with a feather Huzzah and a ultimate GPS board.
Let me go see if I can find the complete sketch. I believe that it was quite lengthy. This might be an exercise in futility as j was mainly interested in getting Softwareserial to work properly and was surprised that this code did not compile cleanly.
I would be wasting your time if I asked for help in modifying the code to eliminate the compiler error. Now that I know what caused it, I might try and fix it as a learning exercise.
jremington:
There are better software serial options that SoftwareSerial, discussed here.
Thank you Remington, that is very helpful and I wish that I had it at the beginning of this silly project.
The Feather Huzzah is not an Arduino, and uses a different processor (ESP8266).
So the SoftwareSerial you are trying to use will never work. The same may hold for the other options I posted in reply #7, as they all use processor specific timer hardware.
You will need to look around for code similar to SoftwareSerial, but specific to that processor.
It would help if you could describe exactly what problem you are having with software serial.