interrupcion

buenas

Alguien sabe como se programa una interrupcion en arduino ,ya que cuando utilizo attachinterrupt(0,codigo de la interrupcion,LOW) pero cuando invoco una funcion que yo hice dentro del codigo de la interrupcion no funciona el codigo, compila y todo pero no me sale lo q espero. Gracias

English

somebody know, how i can use the attachinterrupt(pin, code interrupt, low) because, i can not declare the another function inside code interrupt.

void setup (){
Wire.begin(); //iniciar el bus de I2C
Serial.begin(9600);
pinMode(INTERRUPTPIN, INPUT);
initGyro();
sei();
attachInterrupt(0,interruptfinal,LOW);

}

void interruptfinal() {

byte aux=readByte(GYRO, G_INT_STATUS);
if (aux==00000001 || aux==00000101){

readFrom(GYRO, G_INT_STATUS, 8, gyro);
x = ((gyro[2] << | gyro[3]);
y = ((gyro[4] << | gyro[5]);
z = ((gyro[6] << | gyro[7]);
temp = (gyro[0] << | gyro[1];

}

void readFrom(int device, byte address, int num, byte buff[]) {
Wire.beginTransmission(device);
Wire.send(address);
Wire.endTransmission();

//RESTART CONDITION
Wire.beginTransmission(device);
Wire.requestFrom(device, num);

int i = 0;
while(Wire.available())
{
buff = Wire.receive();
i++;
}
Wire.endTransmission();
}

Si pudieras poner el código en si, nos facilitarías bastante la labor :wink:

void setup (){
Wire.begin(); //iniciar el bus de I2C
Serial.begin(9600);
pinMode(INTERRUPTPIN, INPUT);
initGyro();
sei();
attachInterrupt(0,interruptfinal,LOW);

}

void interruptfinal() {

byte aux=readByte(GYRO, G_INT_STATUS);
if (aux==00000001 || aux==00000101){

readFrom(GYRO, G_INT_STATUS, 8, gyro);
x = ((gyro[2] << | gyro[3]);
y = ((gyro[4] << | gyro[5]);
z = ((gyro[6] << | gyro[7]);
temp = (gyro[0] << | gyro[1];

}

void readFrom(int device, byte address, int num, byte buff[]) {
Wire.beginTransmission(device);
Wire.send(address);
Wire.endTransmission();

//RESTART CONDITION
Wire.beginTransmission(device);
Wire.requestFrom(device, num);

int i = 0;
while(Wire.available())
{
buff = Wire.receive();
i++;
}
Wire.endTransmission();
}

Supongo que el fallo estará aquí:

aux==00000001

Si quieres compararlo con un binario, debes decirle que es un binario, si no, te lo tomará como entero.

Pues quitando el hecho que estas usando la libreria Wire desde dentro de una interrupcion, y estas haciendo una espera activa que consume relativamente mucha CPU... Es muy probable que tengas las interrupciones enmascaradas y que nunca le llegue al micro la interrupcion del I2C.