Interrupt con isr() su imu mpu6050 drotek

Ragazzi ho un problema!
Per altri progetti ho dovuto leggere la mia IMU e lo facevo con un interrupt sul pin2 della mia arduino uno, ma ora sto cercando di farlo con PinChangeInt sul pin analogico 14 o A0. C'è qualcosa che mi sfugge perchè dopo aver sputato fuori la prima rilevazione il programma si blocca. Mi aiutate?

#include <MotorNXT.h>

#include <SPI.h>
#include <math.h>

#define NO_PORTB_PINCHANGES // to indicate that port b will not be used for pin change interrupts
//#define NO_PORTC_PINCHANGES // to indicate that port c will not be used for pin change interrupts
#define NO_PORTD_PINCHANGES // to indicate that port d will not be used for pin change interrupts
//-------- define the above in your sketch, if applicable ------------------------------------------------------
#include <PinChangeInt.h>

#define PIN1 14 //voglio usare il pin A0

#define OUTPUT_READABLE_ROLLPITCHYAW
//e più in basso nel codice ho aggiunto l'isr():

 // enable Arduino interrupt detection, this will execute dmpDataReady whenever there is an interrupt,
    // independing on what this sketch is doing at that moment
    // http://arduino.cc/en/Reference/AttachInterrupt
    Serial.print("Enabling interrupt detection... ");
    // attachInterrupt(interrupt, function, mode) specifies a function to call when an external interrupt occurs
        
     pinMode(PIN1, INPUT); digitalWrite(PIN1, LOW);         
      PCintPort::attachInterrupt(PIN1, &dmpDataReady, RISING);

   // attachInterrupt(0, dmpDataReady, RISING); // the 0 points correctly to INT0 / D2
    // -> if there is an interrupt from MPU-6000 to ATMEGA328, boolean mpuInterrupt will be made true
    byte mpuIntStatus = SPIread(0x3A, ChipSelPin1); // by reading INT_STATUS register, all interrupts are cleared
    Serial.println("done.");

Stampa un singolo risultato, ma nn va in loop con tutte le rilevazioni...
non riesco a capire dove si trova l'errore :fearful:

copia.ino (63.7 KB)

ma dove si blocca il codice? la varibaile delle ISR non diventa mi true?

lesto:
ma dove si blocca il codice? la varibaile delle ISR non diventa mi true?

Ciao Lesto,
il programma stampa un solo valore della variabile x, dopo il quale esce.
A video vedo:
..............................................................
.................................................................
(tutta una serie di confugurazioni...)
DMP ready! Waiting for first data from MPU-6050...

stampa un valore
esce

    #ifdef OUTPUT_READABLE_ROLLPITCHYAW
      // display Euler angles in degrees

      // dmpGetGravity
     float grav_x = 2 * ((q_x * q_z) - (q_w * q_y));
     float grav_y = 2 * ((q_w * q_x) + (q_y * q_z));
     float grav_z = (q_w * q_w) - (q_x * q_x) - (q_y * q_y) + (q_z * q_z);
    
      // roll: (tilt left/right, about X axis)
      rpy_rol = atan(grav_y / (sqrt((grav_x * grav_x) + (grav_z * grav_z))));
      // pitch: (nose up/down, about Y axis)
      rpy_pit = atan(grav_x / (sqrt((grav_y * grav_y) + (grav_z * grav_z))));
      // yaw: (rotate around Z axis)
      rpy_yaw = atan2((2 * q_x * q_y) - (2 * q_w * q_z), (2 * q_w * q_w) + (2 * q_x * q_x) - 1);
      
      x =rpy_pit * 180/M_PI;
      
     Serial.print("Roll angle [degrees]: ");
   //  Serial.print(rpy_rol * 180/M_PI); Serial.print("\t");
     Serial.print(x); Serial.print("\t");
  //   Serial.print(rpy_yaw * 180/M_PI); Serial.println();

prima di sostituire all'interrupt l'isr() il programma stampava all'infinito le singole rilevazioni;
sembra che arrivi soltanto un interrupt e dopo, qualche cosa interrompa il programma, ma non riesco a capire dove!

pinMode(PIN1, INPUT); digitalWrite(PIN1, LOW);

l'INT dell'MPU puo' essere impostato come Totem Pole o Open-Drain
Siccome tu non sai come e' impostato, tanto per non sbagliare si inseriscono le PullUp

e visto che le PullDown su Arduino non esistono, sarebbe il caso di correggere l'errore

@NXT:
la questione delle pull-down che non esistono te l'avevo già fatta presente io, hai ancora lasciato quel pezzo di codice errato nel tuo sorgente... :stuck_out_tongue_closed_eyes:

Ah, ho dato un'occhiata al codice, non userei un interrupt per un compito banale qual è questo:

  while ((mpuInterrupt == false) && (fifoCount < packetSize))
    {
    // do nothing until mpuInterrupt = true or fifoCount >= 42
    }

  // there has just been an interrupt, so reset the interrupt flag, then get INT_STATUS byte
  mpuInterrupt = false;

dove potresti cavartela con una semplice lettura della corrispondete porta logica del chip e del relativo bit

Brunello:

pinMode(PIN1, INPUT); digitalWrite(PIN1, LOW);

l'INT dell'MPU puo' essere impostato come Totem Pole o Open-Drain
Siccome tu non sai come e' impostato, tanto per non sbagliare si inseriscono le PullUp

e visto che le PullDown su Arduino non esistono, sarebbe il caso di correggere l'errore

    // enable Arduino interrupt detection, this will execute dmpDataReady whenever there is an interrupt,
    // independing on what this sketch is doing at that moment
    // http://arduino.cc/en/Reference/AttachInterrupt
    Serial.print("Enabling interrupt detection... ");
    // attachInterrupt(interrupt, function, mode) specifies a function to call when an external interrupt occurs
    
      pinMode(PIN1, INPUT); digitalWrite(PIN1, HIGH); //uso le pull-up        
      PCintPort::attachInterrupt(PIN1, &dmpDataReady, CHANGE); //prova anche FALLING
   // attachInterrupt(0, dmpDataReady, RISING); // the 0 points correctly to INT0 / D2
    // -> if there is an interrupt from MPU-6000 to ATMEGA328, boolean mpuInterrupt will be made true
    byte mpuIntStatus = SPIread(0x3A, ChipSelPin1); // by reading INT_STATUS register, all interrupts are cleared
    Serial.println("done.");

Domani nell'ora di pranzo testerò il programma e posterò la soluzione.
Grazie dell'aiuto intanto : )

dove potresti cavartela con una semplice lettura della corrispondete porta logica del chip e del relativo bit

che io sappia parte un impulso di durata nota ma limitata, per questo si usa l'interrupt.

leo72:
@NXT:
la questione delle pull-down che non esistono te l'avevo già fatta presente io, hai ancora lasciato quel pezzo di codice errato nel tuo sorgente... :stuck_out_tongue_closed_eyes:

Ah, ho dato un'occhiata al codice, non userei un interrupt per un compito banale qual è questo:

  while ((mpuInterrupt == false) && (fifoCount < packetSize))

{
    // do nothing until mpuInterrupt = true or fifoCount >= 42
    }

// there has just been an interrupt, so reset the interrupt flag, then get INT_STATUS byte
  mpuInterrupt = false;



dove potresti cavartela con una semplice lettura della corrispondete porta logica del chip e del relativo bit

@Leo72 ti ringrazio dell'aiuto ma non capisco bene quello che vuoi dire:
http://www.drotek.fr/shop/en/home/42-mpu6050-gyro-accelerometer.html
...with an onboard Digital Motion Processor™ (DMP™) capable of processing complex 9-axis MotionFusion algorithms.
per usare il dmp, come nel mio programma, non ho bisogno di un interrupt per capire che il buffer fifo è pieno?

The FIFO is used with the INT (interrupt) to signal that something is waiting in the fifo.
da qui http://forum.arduino.cc/index.php/topic,113475.0.html

mi spieghi meglio quello che volevi dirmi?

edito per quotare lesto:
ho letto anche io qualcosa del genere in giro per il forum sulla durata nota ma limitata.

lesto:

dove potresti cavartela con una semplice lettura della corrispondete porta logica del chip e del relativo bit

che io sappia parte un impulso di durata nota ma limitata, per questo si usa l'interrupt.

Hai ragione, non pensavo al fatto che l'impulso è di breve durata. Se dura meno del tempo che serve alla lettura del registro, viene perso.

INT_OPEN
When
this bit is
equal to 0, the INT pin is configured as push

pull.
When
this bit is
equal to 1, the INT pin is configured as open drain.
LATCH_INT_EN
When
this bit is
equal to 0, the INT pin emits a 50us long pulse.
W
hen
this bit is
equal to 1, the INT pin is held high until the interrupt is
cleared

Brunello:

pinMode(PIN1, INPUT); digitalWrite(PIN1, LOW);

l'INT dell'MPU puo' essere impostato come Totem Pole o Open-Drain
Siccome tu non sai come e' impostato, tanto per non sbagliare si inseriscono le PullUp

e visto che le PullDown su Arduino non esistono, sarebbe il caso di correggere l'errore

############# MPU-6000 Data Acquisition #############
Initializing SPI Protocol...
...SPI Protocol initializing done.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Initializing Digital Motion Processor (DMP)...
	Writing   DMP memory.......... done.
	Verifying DMP memory.......... success!
	Writing   DMP configuration... done.
	Verifying DMP configuration... success!
	Writing   DMP update 1/7 ..... done.
	Verifying DMP update 1/7 ..... success!
	Writing   DMP update 2/7 ..... done.
	Verifying DMP update 2/7 ..... success!
	Writing   DMP update 3/7 ..... done.
	Verifying DMP update 3/7 ..... success!
	Writing   DMP update 4/7 ..... done.
	Verifying DMP update 4/7 ..... success!
	Writing   DMP update 5/7 ..... done.
	Verifying DMP update 5/7 ..... success!
	Writing   DMP update 6/7 ..... done.
	Verifying DMP update 6/7 ..... success!
	Writing   DMP update 7/7 ..... done.
	Verifying DMP update 7/7 ..... success!
... Digital Motion Processor (DMP) initializing done.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Enabling DMP... done.
Enabling interrupt detection... done.
DMP ready! Waiting for first data from MPU-6000...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Roll angle [degrees]: -2.08
Roll angle [degrees]: -2.08
Roll angle [degrees]: -2.07
Roll angle [degrees]: -2.06
Roll angle [degrees]: -2.06
Roll angle [degrees]: -2.05
Roll angle [degrees]: -2.04
Roll angle [degrees]: -2.04
Roll angle [degrees]: -2.02
Roll angle [degrees]: -2.02
Roll angle [degrees]: -2.01
Roll angle [degrees]: -2.00
Roll angle [degrees]: -1.99
Roll angle [degrees]: -1.98
Roll angle [degrees]: -1.97
Roll angle [degrees]: -1.96
Roll angle [degrees]: -1.95
Roll angle [degrees]: -1.95
Roll angle [degrees]: -1.94
Roll angle [degrees]: -1.93
Roll angle [degrees]: -1.93
Roll angle [degrees]: -1.92
Roll angle [degrees]: -1.91

@Brunello
@leo72
@lesto
Grazie davvero di cuore
Lo dico col sorriso : )
[lettura dati da imu mpu6050 in spi con arduino uno]
!RISOLTO!

CHIUDETE PURE
COME DA TITOLO E' RISOLTO

CAMBIA ARGOMENTO QUINDI APRO UN 3D IN GENERALE