i2c reading with active timer interrupts

Hi,

I have the following Problem. I use on a Project a Arduino Uno with some external Stuff. On the one side I have a SPI driven Matrix which is driven via a Timer based Interrupt on the Arduino. Now I like to read in Data from a i2c based Sensor which generates Low Edges on a interrupt Line. The Interrupt at the Low Edge for the Sensor works without Problem. But now I like to read the data from the Sensor when the Interrupt from the Sensor happens. Every Time I done this the Arduino crashes. What can I do?

My Routine for reading the Sensor looks like this:

int matrixkey2()
{
	int buffer;
	

	Wire.beginTransmission(0x38);

	Wire.requestFrom(0x38, 1);

	delay(100);

	while(Wire.available() == 0);

	buffer = Wire.read();

	if(buffer & 0x01)
	{
		return 1;
	}

	if(pcf_buffer & 0x02)
	{
		return 2;
	}

	if(buffer & 0x04)
	{
		return 3;
	}
	else
	{
		return 0;
	}
	
	
}

If I let this routine running in the loop everything works great. But I like to get this running if the Interrupt on the Falling Edge happens. And if I attach the routine to the Interrupt it goofs completly up when the Interrupt happens.

Berkutta

My Routine for reading the Sensor looks like this:

We don't want to see what it looks like.
We want to it.
All of it.

Interrupt code should be as short and fast as possible and should not call other code that relies on interrupts else the MCU can hang. I suspect if your trying to do all that in the ISR then that's your problem.

Code is exactly as in the Post.

I know that the ISR should be as short as possible. But in this case I need the control of the sensor at the Time of the Interrupt. It's a User Input. So I have no way.

Code is exactly as in the Post

I copied all of your code into a blank IDE window and hit compile:

sketch_feb09a.ino: In function 'int matrixkey2()':
sketch_feb09a:7: error: 'Wire' was not declared in this scope
sketch_feb09a:22: error: 'pcf_buffer' was not declared in this scope