How to handle multiples interrupts

Hi,

I am working on a project that combine I2C and SPI together and i have troubles with infinites loops.

I suppose that i can have an SPI flag interuption while the I2C bus is transmitting,
corrupting the I2C's data that has been sent (some bits are missed while the SPI interrupt routine is being executed),
and thus chain-failling the data-lenght test executed as the condition to get out of the infinite loop like this :

while(lenght not ok) 
{ 
//wait for interrupt
};

Am i correct, and is there any solution ?

Thanks for any help,
LGui

you should split the loops over multiple iterations of void loop()

Some pseudo code

void loop()
{
  // CHECK SPI
  if (SPI data available) 
  {
    read them into a buffer;
  }

  if (I2C data available)
  {
    read them in another buffer
  }

  if (SPIbuffer filled enough)
  {
    process it
  }

  if (I2Cbuffer filled enough)
  {
    process it
  }
}

by programming this way you never (blocking) wait on some event, you handle the events as they happen...

See the most famous tutorial :wink: - http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay -

hope this helps