disquisitioner
New member
Greetings,
I'm brand new to Teensy 3.1 but am keen to come up to speed with it as a better platform for several of my more extensive Arduino projects. I am trying to port over code that depends on using pin change interrupts to detect button pushes as part of controlling the code (and device). I've followed the instructions for installing the Teensy 3.1 IDE environment and using interrupts but can't get even the most basic code to compile properly.
Here's my sample code, which at the moment I'm just trying to get to compile:
===========================
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
volatile boolean newScreen = false;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
// ********************** UTILITY FUNCTIONS **********************
// Convenience utility called within setup() to initialize interrupt handling
// For this test there's just one -- the pushbutton interrupt
void initialize_interrupts()
{
/*
* We're using pin A0 to read the push button so we need to configure the right
* interrupt settings to enable a pin change interrupt on A0. Based on
* http://playground.arduino.cc/Learning/Pins we see that A0 is on Port C
* as PCINT8, with PCMSK of 0 within PCMSK1. The '1' in the PCMKS1 value means
* that we need to clear/enable interrupts and provide an interrupt service
* routine on port/bank 1 overall.
*
* If you want to use a different pin then you'll need to figure out which
* port/mask values to use here...
*/
cli(); // Disable interrupts while adjusting interrupt settings
PCIFR |= bit(PCIF1); // Clear any pending interrupts on Port C (#1)
PCICR |= bit(PCIE1); // Enable interrupts on port 1 (pins A0 -> A5 inclusive)
PCMSK1 |= bit(PCINT8); // Enable interrupts just for pin A0 (which is also PCINT8)
sei(); // Re-enable interrupts now that we have everything set up
}
/*
* We're using a pin change interrupt to read the 'next screen' button which means
* the associated port interrupt service routine will be called here when that
* button's value changes. We therefore handle that as a 'next screen' button push.
* To keep things simple and short here, we just set a flag that'll get handled
* in the main loop.
*/
ISR(PCINT1_vect)
{
// If pin A0 is now HIGH then button was pushed. If LOW the button was released.
if(digitalRead(A0)==HIGH) newScreen = true;
}
=======================================
When I attempt to verify the code using the Arduino 1.6.4 IDE with the Teensy 3.1 board selected I get the following errors:
ISR_test.ino: In function 'void initialize_interrupts()':
ISR_test:36: error: 'PCIFR' was not declared in this scope
In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:15:0,
from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:1,
from ISR_test.ino:6:
ISR_test:36: error: 'PCIF1' was not declared in this scope
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:109:25: note: in definition of macro 'bit'
#define bit(b) (1UL << (b))
^
ISR_test:37: error: 'PCICR' was not declared in this scope
In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:15:0,
from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:1,
from ISR_test.ino:6:
ISR_test:37: error: 'PCIE1' was not declared in this scope
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:109:25: note: in definition of macro 'bit'
#define bit(b) (1UL << (b))
^
ISR_test:38: error: 'PCMSK1' was not declared in this scope
In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:15:0,
from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:1,
from ISR_test.ino:6:
ISR_test:38: error: 'PCINT8' was not declared in this scope
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:109:25: note: in definition of macro 'bit'
#define bit(b) (1UL << (b))
^
ISR_test.ino: At global scope:
ISR_test:49: error: expected constructor, destructor, or type conversion before '(' token
expected constructor, destructor, or type conversion before '(' token
If I specify "Arduino Uno" as the board everything verifies correctly with no errors.
Currently I'm concerned something might have gone wrong in the installation of the Teensyduino as poking around in the installed directories shows a copy of interrupt.h that is zero bytes long . Clearly something is keeping the compiler from finding definitions of PCIFR, PCIF1, etc. Moreover, if I remove the code in initialize_interrupts() I get an error message associated with the use of the ISR() macro:
ISR_test:31: error: expected constructor, destructor, or type conversion before '(' token
expected constructor, destructor, or type conversion before '(' token
On the other hand perhaps interrupt.h is supposed to be zero bytes long with Teensy 3.1 as some other magic is happening. I've done the full installation of the Arduino 1.6.4 IDE and Teensyduino on two different Windows machines and had the exact same problem on both.
In any event, googling all sorts of variations on this error message, teensy 3.1 pin change interrupts, etc. hasn't resulted in any tips as to how I might solve the problem.
Thanks in advance for any help!
David
I'm brand new to Teensy 3.1 but am keen to come up to speed with it as a better platform for several of my more extensive Arduino projects. I am trying to port over code that depends on using pin change interrupts to detect button pushes as part of controlling the code (and device). I've followed the instructions for installing the Teensy 3.1 IDE environment and using interrupts but can't get even the most basic code to compile properly.
Here's my sample code, which at the moment I'm just trying to get to compile:
===========================
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
volatile boolean newScreen = false;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
// ********************** UTILITY FUNCTIONS **********************
// Convenience utility called within setup() to initialize interrupt handling
// For this test there's just one -- the pushbutton interrupt
void initialize_interrupts()
{
/*
* We're using pin A0 to read the push button so we need to configure the right
* interrupt settings to enable a pin change interrupt on A0. Based on
* http://playground.arduino.cc/Learning/Pins we see that A0 is on Port C
* as PCINT8, with PCMSK of 0 within PCMSK1. The '1' in the PCMKS1 value means
* that we need to clear/enable interrupts and provide an interrupt service
* routine on port/bank 1 overall.
*
* If you want to use a different pin then you'll need to figure out which
* port/mask values to use here...
*/
cli(); // Disable interrupts while adjusting interrupt settings
PCIFR |= bit(PCIF1); // Clear any pending interrupts on Port C (#1)
PCICR |= bit(PCIE1); // Enable interrupts on port 1 (pins A0 -> A5 inclusive)
PCMSK1 |= bit(PCINT8); // Enable interrupts just for pin A0 (which is also PCINT8)
sei(); // Re-enable interrupts now that we have everything set up
}
/*
* We're using a pin change interrupt to read the 'next screen' button which means
* the associated port interrupt service routine will be called here when that
* button's value changes. We therefore handle that as a 'next screen' button push.
* To keep things simple and short here, we just set a flag that'll get handled
* in the main loop.
*/
ISR(PCINT1_vect)
{
// If pin A0 is now HIGH then button was pushed. If LOW the button was released.
if(digitalRead(A0)==HIGH) newScreen = true;
}
=======================================
When I attempt to verify the code using the Arduino 1.6.4 IDE with the Teensy 3.1 board selected I get the following errors:
ISR_test.ino: In function 'void initialize_interrupts()':
ISR_test:36: error: 'PCIFR' was not declared in this scope
In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:15:0,
from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:1,
from ISR_test.ino:6:
ISR_test:36: error: 'PCIF1' was not declared in this scope
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:109:25: note: in definition of macro 'bit'
#define bit(b) (1UL << (b))
^
ISR_test:37: error: 'PCICR' was not declared in this scope
In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:15:0,
from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:1,
from ISR_test.ino:6:
ISR_test:37: error: 'PCIE1' was not declared in this scope
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:109:25: note: in definition of macro 'bit'
#define bit(b) (1UL << (b))
^
ISR_test:38: error: 'PCMSK1' was not declared in this scope
In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:15:0,
from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:1,
from ISR_test.ino:6:
ISR_test:38: error: 'PCINT8' was not declared in this scope
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:109:25: note: in definition of macro 'bit'
#define bit(b) (1UL << (b))
^
ISR_test.ino: At global scope:
ISR_test:49: error: expected constructor, destructor, or type conversion before '(' token
expected constructor, destructor, or type conversion before '(' token
If I specify "Arduino Uno" as the board everything verifies correctly with no errors.
Currently I'm concerned something might have gone wrong in the installation of the Teensyduino as poking around in the installed directories shows a copy of interrupt.h that is zero bytes long . Clearly something is keeping the compiler from finding definitions of PCIFR, PCIF1, etc. Moreover, if I remove the code in initialize_interrupts() I get an error message associated with the use of the ISR() macro:
ISR_test:31: error: expected constructor, destructor, or type conversion before '(' token
expected constructor, destructor, or type conversion before '(' token
On the other hand perhaps interrupt.h is supposed to be zero bytes long with Teensy 3.1 as some other magic is happening. I've done the full installation of the Arduino 1.6.4 IDE and Teensyduino on two different Windows machines and had the exact same problem on both.
In any event, googling all sorts of variations on this error message, teensy 3.1 pin change interrupts, etc. hasn't resulted in any tips as to how I might solve the problem.
Thanks in advance for any help!
David