Wemos D1 Interrupt Routine funktioniert nicht?

Gast #6304309
Lesenswert?
• ▲
▼
Hallo,
ich habe folgendes Programm:
1
#include <Wire.h>
2
#include <SparkFun_APDS9960.h>
3

4
// Pins on wemos D1 mini
5
#define APDS9960_INT    D6  //AKA GPIO12 -- Interupt pin
6
#define APDS9960_SDA    D3  //AKA GPIO0
7
#define APDS9960_SCL    D1  //AKA GPIO5
8
#define LED_PIN         D7  //AKA GPIO13 -- LED for showing interrupt
9

10
// Constants
11
#define PROX_INT_HIGH   255 // Proximity level for interrupt
12
#define PROX_INT_LOW    0  // No far interrupt
13

14
// Global variables
15
SparkFun_APDS9960 apds = SparkFun_APDS9960();
16
uint8_t proximity_data = 0;
17
volatile bool isr_flag = 0;
18

19
void setup() {
20

21
  //Start I2C with pins defined above
22
  Wire.begin(APDS9960_SDA,APDS9960_SCL);
23
  
24
  // Set LED as output
25
  pinMode(LED_PIN, OUTPUT);
26
  pinMode(APDS9960_INT, INPUT);
27
  
28
  // Initialize Serial port
29
  Serial.begin(115200);
30
  Serial.println();
31
  Serial.println(F("---------------------------------------"));
32
  Serial.println(F("SparkFun APDS-9960 - ProximityInterrupt"));
33
  Serial.println(F("---------------------------------------"));
34
  
35
  // Initialize interrupt service routine
36
  attachInterrupt(APDS9960_INT, interruptRoutine, FALLING);
37
  
38
  // Initialize APDS-9960 (configure I2C and initial values)
39
  if ( apds.init() ) {
40
    Serial.println(F("APDS-9960 initialization complete"));
41
  } else {
42
    Serial.println(F("Something went wrong during APDS-9960 init!"));
43
  }
44
  
45
  // Adjust the Proximity sensor gain
46
  if ( !apds.setProximityGain(PGAIN_8X) ) {
47
    Serial.println(F("Something went wrong trying to set PGAIN"));
48
  }
49
  
50
  // Set proximity interrupt thresholds
51
  if ( !apds.setProximityIntLowThreshold(PROX_INT_LOW) ) {
52
    Serial.println(F("Error writing low threshold"));
53
  }
54
  if ( !apds.setProximityIntHighThreshold(PROX_INT_HIGH) ) {
55
    Serial.println(F("Error writing high threshold"));
56
  }
57
  
58
  // Start running the APDS-9960 proximity sensor (interrupts)
59
  if ( apds.enableProximitySensor(true) ) {
60
    Serial.println(F("Proximity sensor is now running"));
61
  } else {
62
    Serial.println(F("Something went wrong during sensor init!"));
63
  }
64
}
65

66
void loop() {
67
  
68
  // If interrupt occurs, print out the proximity level
69
  if ( isr_flag == 1 ) {
70
  
71
    // Read proximity level and print it out
72
    if ( !apds.readProximity(proximity_data) ) {
73
      Serial.println("Error reading proximity value");
74
    } else {
75
      Serial.print("Proximity detected! Level: ");
76
      Serial.println(proximity_data);
77
    }
78
    
79
    // Turn on LED for a half a second
80
    digitalWrite(LED_PIN, HIGH);
81
    delay(500);
82
    digitalWrite(LED_PIN, LOW);
83
    
84
    // Reset flag and clear APDS-9960 interrupt (IMPORTANT!)
85
    isr_flag = 0;
86
    if ( !apds.clearProximityInt() ) {
87
      Serial.println("Error clearing interrupt");
88
    }
89
    
90
  }
91
}
92

93
ICACHE_RAM_ATTR void interruptRoutine() {
94
  isr_flag = 1;
95
  //Serial.println("Interrupt");
96
}


Leider löst die Interrupt Routine nicht aus :(
Was ist falsch?
Gast #6304754
Lesenswert?
• ▲
▼
Probiere mal:
> attachInterrupt(digitalPinToInterrupt(APDS9960_INT), interruptRoutine, FALLING);

Serial.println() innerhalb der ISP wird wohl nur mit Glück 
funktionieren.

Falls das nicht hilft, prüfe folgendes:

Bist du sicher, dass die loop() überhaupt ausgeführt wird?
Welche Spannung misst du am Pin D6 im Ruhezustand, und in dem Moment, wo 
der Interrupt ausgelöst werden sollte?

Antwort schreiben

Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt. Bitte hier nur auf die ursprüngliche Frage antworten, für neue Fragen einen neuen Beitrag erstellen.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.