High speed loop

Hello, I'm quitte new with arduino so first excuse me if the question is stupid !

I use a custom board with an Arduino SAMD21 (M0 bootloader) and I just make this code to check the state of an interrupt, and I have some problem with the while(!DATA_READY);

#define PIN_INTERRUPT        5
boolean DATA_READY = false;


void detectionACTIVATE() {
  SerialUSB.println("!PWR");
  DATA_READY = true;
}

void setup() {
attachInterrupt(PIN_INTERRUPT, detectionACTIVATE, RISING);
SerialUSB.begin(9600);
SerialUSB.println("ready");
}

void loop() {
while(!DATA_READY);
SerialUSB.println("PASS");
DATA_READY = false;
}

The result; the interrupt is detected without any problem in the Serial monitor but the while doesn't break, I never get "PASS"... After few search, I add a delay after the while like this : while(!DATA_READY) delay(1); and all works fine now but as I would like to use a system with 3 sensors sampled at 500SPS, I cannot stay at 1ms delay...

I tried delayMicroseconds(1), but I it doesn't works... it seem that my USB communication disconnect when I do that, even with delayMicroseconds(1000);

Quitte strange... maybe can you help me or suggest me a better approch of the interrupt detection? Thank you and sorry for the bad english.

Pierre

Maybe make DATA_READY volatile as it is used both in the ISR and in the main program.

It works without delay ! thank you very much :D