I'm having problems trying to get interrupts made for AVR working on the Teensy.
This is the part of the code that's giving me trouble
I get
I have tried #include avr/io.h and interrupt.h, but that doesn't do anything. Interrupt.h is empty.
Not sure what to do next. The http://www.pjrc.com/teensy/interrupts.html info has the PCICR etc. names, but I'm not sure what to do with them, so I'm stuck.
This is the part of the code that's giving me trouble
Code:
#define PIN_MASK 0b00001100
void NazaDecoderLib::startPwmReader()
{
pinMode(2, INPUT_PULLUP); // Pitch (Arduino D2 <-> Naza F2)
pinMode(1, INPUT_PULLUP); // Roll (Arduino D3 <-> Naza F1)
cli();
PCICR = 1 << PCIE2;
PCMSK2 = PIN_MASK;
sei();
}
void NazaDecoderLib::pwmInterruptHandler()
{
uint8_t bit;
uint8_t curr;
uint8_t mask;
uint32_t currentTime;
uint32_t time;
// get the pin states for the indicated port.
curr = PIND & PIN_MASK;
mask = curr ^ pcIntLast;
pcIntLast = curr;
currentTime = micros();
// mask is pcint pins that have changed.
for (uint8_t i = 0; i < 2; i++) {
bit = 0b00000100 << i;
if (bit & mask) {
// for each pin changed, record time of change
if (bit & pcIntLast) {
time = currentTime - pwmData[i].fallTime;
pwmData[i].riseTime = currentTime;
if ((time >= 10000) && (time <= 26000))
pwmData[i].edge = 1;
else
pwmData[i].edge = 0; // invalid rising edge detected
}
else {
time = currentTime - pwmData[i].riseTime;
pwmData[i].fallTime = currentTime;
if ((time >= 800) && (time <= 2200) && (pwmData[i].edge == 1)) {
pwmData[i].lastGoodWidth = time;
pwmData[i].edge = 0;
}
}
}
}
}
ISR(PCINT2_vect)
{
NazaDecoder.pwmInterruptHandler();
}
I get
Code:
NazaDecoderLib.cpp: In member function 'void NazaDecoderLib::startPwmReader()':
NazaDecoderLib.cpp:139:3: error: 'PCICR' was not declared in this scope
NazaDecoderLib.cpp:139:16: error: 'PCIE2' was not declared in this scope
NazaDecoderLib.cpp:140:3: error: 'PCMSK2' was not declared in this scope
NazaDecoderLib.cpp: At global scope:
NazaDecoderLib.cpp:184:4: error: expected constructor, destructor, or type conversion before '(' token
I have tried #include avr/io.h and interrupt.h, but that doesn't do anything. Interrupt.h is empty.
Not sure what to do next. The http://www.pjrc.com/teensy/interrupts.html info has the PCICR etc. names, but I'm not sure what to do with them, so I'm stuck.