Hi,
I'm new user of arduino and i chose Yun,
I need 4 interruptions for my application,
I chose INT0 and 1 but i need 2 more.
As i want tu use the bridge INT3 (Tx), 2(Rx) and 6 (handshake) seem unusabled.
So i tried to use 2 PinChange Interruptions.
My sketch seems to work with PC_Int7:4 but fails working with PCINT3 and 1 but 2.
(works for PCINT2). The entrance swings.
So, my question is : Is-it possible to use PCINT3:1 (port PB3:1 on ATmega U32 pins 11:9) and what's the best way?
in fact, these pins are connected to the ICSP connector and the processor U1 through a bi-directionnal buffer which OE pin's state is unknown.
Thanks,
Kind regards.
See my code below...
PS : i also tried PCINT7:4 with PinChangeInterrupt's library
// PCINT test
//#define PIN_CHANGE_INT_LIB
#ifdef PIN_CHANGE_INT_LIB
#include <PinChangeInt.h>
#endif PIN_CHANGE_INT_LIB
#define PIN08_PCINT4 8
#define PIN09_PCINT5 9
#define PIN10_PCINT6 10
#define PIN11_PCINT7 11
// Notice that values that get modified inside an interrupt, that I wish to access
// outside the interrupt, are marked "volatile". It tells the compiler not to optimize
// the variable.
volatile uint16_t PCINTx_interruptCount=0; // The count will go back to 0 after hitting 65535.
void setup()
{
Serial.begin(9600);
while (!Serial); // do nothing until the serial monitor is opened
Serial.println("GO !");
InitialiseIO();
#ifdef PIN_CHANGE_INT_LIB
attachPinChangeInterrupt(PIN11_PCINT7, PCINTx_interruptFunction, FALLING);
#else PIN_CHANGE_INT_LIB
InitialiseInterrupt();
#endif PIN_CHANGE_INT_LIB
}
volatile uint16_t PCINTx_interruptCount_Cpy_old;
void loop() {
volatile uint16_t PCINTx_interruptCount_Cpy;
uint8_t oldSREG; // Status Register
// to read a variable which the interrupt code writes, we
// must temporarily disable interrupts, to be sure it will
// not change while we are reading. To minimize the time
// with interrupts off, just quickly make a copy, and then
// use the copy while allowing the interrupt to keep working.
//noInterrupts();
//GlobalVar_Copy = GlobalVar;
//interrupts();
// Interrupt Variable's read must be protected.
// Prevent Variable's modification during read operation.
oldSREG = SREG;
cli();
PCINTx_interruptCount_Cpy = PCINTx_interruptCount;
// Restore interrupts
SREG = oldSREG;
if(PCINTx_interruptCount_Cpy != PCINTx_interruptCount_Cpy_old)
{
Serial.print("PCINTx_interruptCount : ");
Serial.println(PCINTx_interruptCount_Cpy);
delay(1000);
}
PCINTx_interruptCount_Cpy_old = PCINTx_interruptCount_Cpy;
}
void InitialiseIO(){
// pinMode(PIN11_PCINT7, INPUT_PULLUP); // Configure the pin as an input, and turn on the pullup resistor.
// pinMode( PIN11_PCINT7, INPUT); // Configure the pin as an input
// digitalWrite( PIN11_PCINT7, HIGH); // Internal Pull-Up
DDRB = 0x00; //PCINT7:0 == input
PORTB = 0xFF; //PCINT7:0 == Pull-Up
}//void InitialiseIO()
#ifndef PIN_CHANGE_INT_LIB
void InitialiseInterrupt(){
cli(); // switch interrupts off while messing with their settings
// EICRA = 0x2; // Falling edge of INT0 generates an interrupt request
// EICRB = 0xFF; // Any edge of INT0 generates an interrupt request
EIMSK = 0; // Disable INTx interrupt enbale
PCICR = 1; // PCIE0 = 1 : Enable PCINT0 interrupt
PCIFR = 1; // PCIF0 = 1 : Clear interrupt flags PCIFR
// PCMSK0 = 0x80; //Enable PCINT7 only !!!
// PCMSK0 = 0x82; //Enable PCINT7 & PCINT1 only !!!
PCMSK0 = 0x88; //Enable PCINT7 & PCINT3 only !!!
// PCMSK0 = 0x84; //Enable PCINT7 & PCINT2 only !!!
sei(); // turn interrupts back on
}//InitialiseInterrupt()
// Do not use any Serial.print() in interrupt subroutines. Serial.print() uses interrupts,
// and by default interrupts are off in interrupt subroutines. Interrupt routines should also
// be as fast as possible. Here we just increment a counter.
ISR(PCINT0_vect) { // Interrupt service routine. Every single PCINT7:0 change
// will generate an interrupt: but this will always be the same interrupt routine
PCINTx_interruptCount++;
// PCIFR = 1; // PCIF0 = 1 : Clear interrupt flags PCIFR
}//PCINT0_vect()
#endif PIN_CHANGE_INT_LIB
void PCINTx_interruptFunction() {
PCINTx_interruptCount++;
}