After finding out about the situation with pin7 from this tutorial:
https://forum.sparkfun.com/viewtopic.php?f=32&t=35847
void setup(){
EICRB |= (1<<ISC60)|(0<<ISC61); // sets the interrupt type for EICRB (INT6).
// EICRA sets interrupt type for INT0...3
/*
ISCn0 ISCn1 Where n is the interrupt. 0 for 0, etc
0 0 Triggers on low level
1 0 Triggers on edge
0 1 Triggers on falling edge
1 1 Triggers on rising edge
*/
EIMSK |= (1<<INT6); // activates the interrupt. 6 for 6, etc
void loop(){
//do other things here
}
ISR(INT6_vect) {
// interrupt code goes here
}
I have set:
EICRB |= (0<<ISC60)|(0<<ISC61);
Because I need it to be triggered on LOW.
I could still not get it work on the micro. IF I use the pin as regular input pin I can clearly see LOW/HIGHs on pin 7 with digitalread.
I have a sensor attached there which goes LOW in case it is triggered.
I wonder if anybody knows what else can I try to get it work. I already hardwired everything in my circuit board, there are no more free interrupts and no way to change them.
-
4ORing with 0 does nothing.Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2016年07月19日 07:36:28 +00:00Commented Jul 19, 2016 at 7:36
-
And did you define an ISR?Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2016年07月19日 07:40:14 +00:00Commented Jul 19, 2016 at 7:40
1 Answer 1
I've used following code and loopback from pin 8 to pin 7:
// loopback: pin 8 -> pin 7
void setup() {
pinMode(7, INPUT_PULLUP);
pinMode(8, OUTPUT);
pinMode(LED_BUILTIN_TX, OUTPUT); // to see pin 8 logic level on TX led
pinMode(LED_BUILTIN, OUTPUT); // toggled by ISR
EICRB |= _BV(ISC60); // Triggers on edge
EIMSK |= _BV(INT6); // activates the interrupt
}
ISR(INT6_vect) {
PINC = _BV(PC7); // toggle led 13 (@ PC7)
}
void loop() {
digitalWrite(8, HIGH);
digitalWrite(LED_BUILTIN_TX, HIGH);
delay(500);
digitalWrite(8, LOW);
digitalWrite(LED_BUILTIN_TX, LOW);
delay(500);
}
And it works perfectly. Only problem I can imagine is to figure out correctly which pin is really 7 as label is on the right side of pin (not under nor left).