Skip to content

Commit

Permalink
Node noch mit Interruptsteuerung. Problem: Nach einigen Läufen wird d…
Browse files Browse the repository at this point in the history
…ie 51er Message nicht mehr gesendet!
  • Loading branch information
Norbert committed Dec 5, 2023
1 parent ae1c18a commit 2e26ede
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 26 deletions.
93 changes: 72 additions & 21 deletions avr/Node/Node.ino
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
#include "LCD5110.h"
#endif

#if defined(DEBUG_DISPLAY_5110)
#include "LCD5110_Logwriter.h"
#endif

#if defined(SENSOR_18B20)
#include <OneWire.h>
#include <DallasTemperature.h>
Expand Down Expand Up @@ -106,7 +110,11 @@ float u_ref;

ISR(WDT_vect) { watchdogEvent(); }

#if defined(DISPLAY_ALL)
#if defined(DEBUG_DISPLAY)
LCD5110 lcd(N5110_RST,N5110_CE,N5110_DC,N5110_DIN,N5110_CLK);
#endif

#if defined(DISPLAY_ALL)
bool displayIsSleeping = false;
#if defined(DISPLAY_5110)
LCD5110 lcd(N5110_RST,N5110_CE,N5110_DC,N5110_DIN,N5110_CLK);
Expand Down Expand Up @@ -237,9 +245,12 @@ RF24 radio(RADIO_CE_PIN,RADIO_CSN_PIN);

#if defined (ZAEHLERINTERRUPT)
void intZaehler_ISR() {
#ifdef DEBUG_STATUSLED_INT
digitalWrite(STATUSLED,! digitalRead(INTPIN));
#endif
if ( digitalRead(INTPIN) == LOW ) {
intStatusStack = (intStatusStack << 1);
if ( (intStatusStack & 0b00001110) == 0b00001110 ) {
if ( (intStatusStack & 0b00000111) == 0b00000111 ) {
intStatusStack = 0b00000000;
intZaehlerUI++;
intZaehlerF = (float)intZaehlerUI / 100;
}
Expand Down Expand Up @@ -878,7 +889,7 @@ void init_eeprom(bool reset_eeprom) {
}

void setup(void) {
delay(500);
delay(50);

#if defined(STATUSLED)
pinMode(STATUSLED, OUTPUT);
Expand All @@ -896,11 +907,11 @@ void setup(void) {
#endif
intSumSleepTime = 0;
intStatusStack = 0;
attachInterrupt(digitalPinToInterrupt(INTPIN), intZaehler_ISR, FALLING);
attachInterrupt(digitalPinToInterrupt(INTPIN), intZaehler_ISR, CHANGE);
#endif

// Init EEPROM
init_eeprom(false);
init_eeprom(false);

#if defined(DISCHARGE3_PIN)
pinMode(DISCHARGE3_PIN, OUTPUT);
Expand Down Expand Up @@ -979,6 +990,7 @@ init_eeprom(false);
}
neopixels.show();
#endif

#if defined(RF24NODE)
radio.begin();
delay(100);
Expand All @@ -997,7 +1009,9 @@ init_eeprom(false);
radio.printDetails();
#endif
#endif //RF24NODE

delay(100);

#if defined(RELAIS_1)
digitalWrite(RELAIS_1,RELAIS_OFF);
#endif
Expand All @@ -1010,10 +1024,17 @@ init_eeprom(false);
#if defined(RELAIS_4)
digitalWrite(RELAIS_4,RELAIS_OFF);
#endif

#if defined(NEOPIXEL)
neopixels.clear();
neopixels.show();
#endif

#if defined(DEBUG_DISPLAY_5110)
lcd.begin();
lcd.clear();
#endif

#if defined(DISPLAY_ALL)
#if defined(DISPLAY_5110)
lcd.begin();
Expand All @@ -1031,7 +1052,6 @@ init_eeprom(false);
lcd.draw();
delay(1000);
lcd.clear();
#endif
#if defined(MONITOR)
monitor(1000);
#endif
Expand All @@ -1041,7 +1061,7 @@ init_eeprom(false);
draw_therm(THERM_X0, THERM_Y0);
draw_hb_countdown(8);
#endif
loopcount = 0;
#endif
#if defined(STATUSLED)
digitalWrite(STATUSLED,STATUSLED_OFF);
#endif
Expand All @@ -1050,6 +1070,7 @@ init_eeprom(false);
pingTest();
sendRegister();
#endif
loopcount = 0;
}

// Start of DISPLAY_ALL Block
Expand Down Expand Up @@ -1536,6 +1557,9 @@ void do_transmit(uint8_t max_tx_loopcount, uint8_t msg_type, uint8_t msg_flags,
#if defined(DEBUG_SERIAL_RADIO)
Serial.print("TX: ");
printPayload(&s_payload);
#endif
#if defined(DEBUG_STATUSLED_RADIO_TX)
digitalWrite(STATUSLED, STATUSLED_ON);
#endif
radio.write(&s_payload, sizeof(s_payload));
delay(1);
Expand All @@ -1555,11 +1579,12 @@ void do_transmit(uint8_t max_tx_loopcount, uint8_t msg_type, uint8_t msg_flags,
}
#endif
if ( radio.available() ) {
#if defined(DEBUG_SERIAL_RADIO)
Serial.print("RX: ");
#endif
//#if defined(DEBUG_SERIAL_RADIO)
// Serial.print("RX: ");
//#endif
radio.read(&r_payload, sizeof(r_payload));
#if defined(DEBUG_SERIAL_RADIO)
Serial.println();
printPayload(&r_payload);
if (r_payload.node_id != RF24NODE) {
Serial.println("Wrong Node, Message dropped!");
Expand Down Expand Up @@ -1599,6 +1624,9 @@ void do_transmit(uint8_t max_tx_loopcount, uint8_t msg_type, uint8_t msg_flags,
}
} //radio.available
}
#if defined(DEBUG_STATUSLED_RADIO_TX)
digitalWrite(STATUSLED, STATUSLED_OFF);
#endif
tx_loopcount++;
}
}
Expand Down Expand Up @@ -1780,9 +1808,21 @@ void loop(void) {
Serial.print("aufbereitet: ");
Serial.println(intZaehlerF);
#endif
#endif
#if defined(DEBUG_SERIAL_RADIO)
Serial.println("Loop: Start transmit");
#endif
#if defined(DEBUG_STATUSLED_RADIO)
digitalWrite(STATUSLED, STATUSLED_ON);
#endif
do_transmit(eeprom.max_sendcount, payloadNo == 0 ? PAYLOAD_TYPE_HB : PAYLOAD_TYPE_HB_F, mk_flags(true), 0, 0);
exec_jobs();
#if defined(DEBUG_STATUSLED_RADIO)
digitalWrite(STATUSLED, STATUSLED_OFF);
#endif
#if defined(DEBUG_SERIAL_RADIO)
Serial.println("Loop: End transmit");
#endif
radio.stopListening();
delay(1);
radio.powerDown();
Expand All @@ -1798,19 +1838,29 @@ void loop(void) {
#if defined(DISPLAY_ALL)
display_refresh();
#endif
#ifdef ZAEHLERINTERRUPT
/*
* Sonderbehandlung für Interruptbasierte Zähler
*/
#ifdef ZAEHLERINTERRUPT
intStatusStack = (intStatusStack << 1) | (digitalRead(INTPIN)? 1:0);
intStatusStack = (intStatusStack << 1) | (digitalRead(INTPIN)? 0b00000001:0b00000000);
if ( (intStatusStack & 0b00000111) == 0b00000111 ) {
intSumSleepTime = 0;
while (intSumSleepTime < eeprom.sleeptime) {
dosleep(9);
intSumSleepTime += 8;
SLEEPTYPE(1000); //sleep 1s
intSumSleepTime += 1;
#ifdef DEBUG_SERIAL
Serial.print("Loop: "); Serial.print(loopcount); Serial.print(" intSumSleepTime: "); Serial.println(intSumSleepTime);
#endif
#ifdef DEBUG_DISPLAY
lcd.print("L "); lcd.print(loopcount); lcd.print(" PortH "); lcd.println(intSumSleepTime);
#endif
}
} else {
dosleep(5);
SLEEPTYPE(61); //sleep 60ms
if (loopcount > 0) loopcount--;
#ifdef DEBUG_DISPLAY
lcd.print("L "); lcd.print(loopcount); lcd.print(" PortL "); lcd.println(intSumSleepTime);
#endif
}
#else
/*
Expand All @@ -1836,13 +1886,14 @@ void loop(void) {
#if defined(DISCHARGE1)
}
#endif
#endif //ZAEHLERINTERRUPT
/*
* ENDE Sonderbehandlung für Interruptbasierte Zähler
* ENDE Trennung: Interruptbasierte Zähler / normale Nodes
*/
#endif //ZAEHLERINTERRUPT
loopcount++;
#ifdef ZAEHLERINTERRUPT
intSumSleepTime = 0;
#endif
if ( loopcount > eeprom.emptyloops ) loopcount = 0;
#ifdef DEBUG_SERIAL
Serial.print("Loopcount: ");
Serial.println(loopcount);
#endif
}
14 changes: 9 additions & 5 deletions avr/Node/Node_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@
#endif
//-----------------------------------------------------
#if defined(GASZAEHLERNODE)
//#define DEBUG_STATUSLED_RADIO_TX
#define RF24NODE 111
#define EEPROM_VERSION 9
#define EEPROM_VERSION 3
#define ZAEHLERINTERRUPT
#define ZAEHLER_LO_CHANNEL 11
#define ZAEHLER_HI_CHANNEL 12
Expand All @@ -233,16 +234,19 @@
#define ZAEHLER_HI_SET_CHANNEL 52
#define SENSOR_BOSCH
#define SLEEPTIME 60
#define EMPTYLOOPS 4
#define EMPTYLOOPS 1
#define LOW_VOLT_LEVEL 2.0
#define ZAEHLERSTART 285134
#define ZAEHLERSTART 286710
#define SLEEPTYPE sleep4ms
#endif
//-----------------------------------------------------
// Testnodes
//-----------------------------------------------------
#if defined(ZAEHLER_TEST_198)
#define DEBUG_SERIAL_SENSOR
#define DEBUG_SERIAL_RADIO
//#define DEBUG_DISPLAY_5110
//#define DEBUG_DISPLAY
#define SLEEPTYPE delay
#define RF24NODE 198
#define EEPROM_VERSION 3
Expand All @@ -254,7 +258,7 @@
#define ZAEHLER_HI_SET_CHANNEL 52
#define SENSOR_BOSCH
#define SLEEPTIME 60
#define EMPTYLOOPS 4
#define EMPTYLOOPS 1
#define LOW_VOLT_LEVEL 2.0
//#define SLEEP4MS_FAC 950
#endif
Expand Down Expand Up @@ -606,7 +610,7 @@
//
// Definitions for Nokia 5110 Display
//
#if defined(DISPLAY_5110)
#if defined(DISPLAY_5110) || defined(DEBUG_DISPLAY_5110)
// DISPLAY Nokia 5110 is 84 * 48 Pixel
#ifndef N5110_CLK
#define N5110_CLK 7
Expand Down

0 comments on commit 2e26ede

Please sign in to comment.