You don't have to use: #include <Arduino.h>
The Wire.readBytes() needs a cast to (byte *) for the first parameter.
I am not able to check if the buffer works in all circumstances with the ATOMIC blocks, volatile and static variables.
The normal way is:
volatile bool flag;
volatile struct myData ...
void loop()
{
if (flag)
{
noInterrupts();
make a copy of the data // memcpy to local struct
flag = false;
interrupts();
use the copy from now on
}
}
It is just the data and the flag. That is easier to check in case of a bug.
The interrupt routine can check the flag and increase an error count if the flag was not cleared yet.