Arduino 1.8.5 on a 2560 Mega
Yes, you are right. I see that this syntax is valid for the DUE only.
detachInterrupt(1);
Does works with en as well sinse en is just an const int ... But thank you it makes more sense like this.
The code below seems to work well. Volatile interruptFlag seemed to do the trick.
Thank you all very much!
const int en = 3; // Interupt Pin
byte data = 0;
byte cont = 0;
char dArr[100] = {};
int bufLen = 20;//Number of times to call interupt routine
int i = 0;
volatile bool interuptFlag = false; // Indicate if interupt is still activ
//Interupt function on falling enable pin
void enCha()
{
//Read Ports
data = PINA;
cont = PINB;
if ((cont << 6) == 0b10000000)
{
dArr[i] = char(data);
i++;
if (i > bufLen)
{
interuptFlag = true;
i = 0;
detachInterrupt(1);
}
}
}
void setup()
{
Serial.begin(2000000);
}
void loop()
{
attachInterrupt(digitalPinToInterrupt(en), enCha, FALLING); //Interupt on falling edge
while (interuptFlag == false) {};
//Print data
String bufStr(dArr);
Serial.println(bufStr);
//Reset
interuptFlag = false;
}