isr visited prior to corresponding interrupts being enabled?

Hello,
upon program start, In my isr, the variable
sensorState[sensorStateIndex].timeStamp=epochLocal
is updated before the corresponding interrupts are being enabled.

Here is the code

declarations

...
ISR(PCINT0_vect){sensorISR();}
ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect));
ISR(PCINT2_vect, ISR_ALIASOF(PCINT0_vect));
...

setup

...
get epoch from Internet, setup epochLocal
...
initInterrupts()
...

initInterrupts

void initInterrupts(){
cli();

attachInterrupt (0, sensorISR, CHANGE);
attachInterrupt (1, sensorISR, CHANGE);
attachInterrupt (2, sensorISR, CHANGE);
attachInterrupt (3, sensorISR, CHANGE);
attachInterrupt (4, sensorISR, CHANGE);
attachInterrupt (5, sensorISR, CHANGE);


//INT0-5 control
DDRD&=0x0f; //PORTD0-3 inputs
PORTD|=0x0f; //pull ups on pins PORTD0-3

DDRE&=0xcf;//PORT E4-5 as inputs
PORTE|=0x30;//pull ups on PORTE 4-5
//guess enabled by the attachInterrupts

//PCINT0-2 control
DDRB&=0x9f; // set pin portB 5-6 as input, leave other untouched
PORTB|=0x60;// pull ups on pins 5-6
PCMSK0|=0x60;//enable interrupts on portB 5-6
 
DDRJ&=0xfc; // pins 0-1 input 
PORTJ|=0x03;// pins 0-1 pull ups
PCMSK1|=0x06;// set PCMSK1_1-2. PCMSK1_0-PCINT8-PE0, PCMSK1_1-PCINT9-PJ0, PCMSK1_2-PCINT10-PJ1, PCMSK1_3-PCINT11-PJ2 ... PCMSK1_7-PCINT15-PJ6

DDRK=0x00; //inputs
PORTK=0xff;//add pull ups
PCMSK2=0xff;// enable interrupts on all port k

PCICR=0b00000111; //enable PCINT0-2

EIFR=0Xff; //clear all 8 bits interrupt flags of ext interrupt eifr
PCIFR=0x07; //clear all 3 bits interrupt flug of pin change interrupr
sei();
}

isr

void sensorISR(){
...
  sensorState[sensorStateIndex].timeStamp=epochLocal;
... 
}

So, the assumption is that before initInterrupt is executed, sensorISR won't be visited(!) and if so, once visited, epochLocal has the correct time and so for the first element of sensorState array
In practice, oftentimes, if a sensor is stimulated after the program starts and before initInterrupts is executed, the value loaded into sensorState is the initial value of epochLocal - either compilerr's generated 0 or any other value i assign to it in the declaration

Post your complete code as a single item - it is too difficult mentally to join your snippets. If it is too long add the .INO file as an attachment.

...R

ISR() creates, sets up and arms the interrupt from the start of the program. IE before setup is called.

DO NOT mix attachinterrupt() and ISR itis pointless.

Mark

holmes4:
ISR() creates, sets up and arms the interrupt from the start of the program. IE before setup is called.

DO NOT mix attachinterrupt() and ISR itis pointless.

Mark

I don't understand, do you mean that the code in sensorISR is executed before setup? Before the interrupts are enabled by the code of initInterrupts?

Robin2:
Post your complete code as a single item - it is too difficult mentally to join your snippets. If it is too long add the .INO file as an attachment.

...R

Attached

The question is how come the sensorInterrupt is visited before the epochLocal is setup by setup() so that the first entry of sensorState wrongly contains the power up value of epochLocal, here set to 3 Sep 2015 01:01:01

guy_lib.h (415 Bytes)

integrated2_08_public.ino (26.9 KB)

ISR creates, setsup and arms the interrupt BEFORE any part of your code is run!

Mark