olikraus / u8glib

Arduino Monochrom Graphics Library for LCDs and OLEDs
https://github.com/olikraus/u8glib/wiki
Other
1.24k stars 313 forks source link

Watchdog #482

Open spa-sam opened 6 years ago

spa-sam commented 6 years ago

Watchdog not work! Atmega328p, Nokia 5110. If Watchdog is triggered then the microcontroller restarts and freeze (or enters the reboot cycle?!). It does not depend whether there is a bootloader or not.

The display of the Nokia 5110 with the library from Adafruit wdt works.

#include <avr/wdt.h>
#include "U8glib.h"
U8GLIB_PCD8544 u8g(19, 18, 16, 17, 15);  // CLK=19, DIN=18, CE=16, DC=17, RST=15

void setup() {
wdt_enable(WDTO_8S);
wdt_reset();

 u8g.firstPage();
do {  
    u8g.setFont(u8g_font_6x12);
    u8g.setPrintPos(1,8);
    u8g.print("Start...");  
                    } while(u8g.nextPage());
delay(2000);
}

void loop() {

wdt_reset();
u8g.firstPage();
do {  
    u8g.setFont(u8g_font_6x12);
    u8g.setPrintPos(1,8);
    u8g.print("ReStarting...");  
                    } while(u8g.nextPage());
delay(9000);
}
olikraus commented 6 years ago

hmm... so what shell I do?

Dominiquechai commented 6 years ago

Try like as : void setup() { MCUSR = 0; cli(); wdt_reset(); wdt_enable(WDTO_8S); WDTCSR = (1<<WDCE) | (1<<WDE); WDTCSR = (1<<WDE); WDTCSR = (1<<WDIE); // Watchdog interrrupt enabled. MCUSR = 0; sei(); } I don't know why wdt_enable() does not work normally. But, above code work well.

porumatu commented 5 years ago

Hello I have the same problem with u8g library. Code above didn't work, could you please solve this problem?

AnHardt commented 5 years ago

Unlikely. Almost always it's user error, sometimes the implementation of wdt_enable().

In the first message of this thread the user activates the watchdog with WDTO_8S, what means; reset the MC if wdt_reset() is not called at least every 8 seconds. Than he delays for 9 seconds.

WDTO_4S is not available for all avr processors (only on: ATtiny2313, ATtiny24, ATtiny44, ATtiny84, ATtiny84A, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861, ATmega48, ATmega88, ATmega168, ATmega48P, ATmega88P, ATmega168P, ATmega328P, ATmega164P, ATmega324P, ATmega644P, ATmega644, ATmega640, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega8HVA, ATmega16HVA, ATmega32HVB, ATmega406, ATmega1284P, AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, AT90PWM81, AT90PWM161, AT90USB82, AT90USB162, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, ATtiny48, ATtiny88.) WDTO_8S is not available for all avr processors (only on: ATtiny2313, ATtiny24, ATtiny44, ATtiny84, ATtiny84A, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861, ATmega48, ATmega48A, ATmega48PA, ATmega88, ATmega168, ATmega48P, ATmega88P, ATmega168P, ATmega328P, ATmega164P, ATmega324P, ATmega644P, ATmega644, ATmega640, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega8HVA, ATmega16HVA, ATmega32HVB, ATmega406, ATmega1284P, ATmega2564RFR2, ATmega256RFR2, ATmega1284RFR2, ATmega128RFR2, ATmega644RFR2, ATmega64RFR2 AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, AT90PWM81, AT90PWM161, AT90USB82, AT90USB162, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, ATtiny48, ATtiny88, ATxmega16a4u, ATxmega32a4u, ATxmega16c4, ATxmega32c4, ATxmega128c3, ATxmega192c3, ATxmega256c3.)

In both cases the bits for setting this are distributed to 2 registers. 3 bits in the one 1 in the other. Older implementations of wdt_enable() try to set the 4 bit value on 3 bits in the first register. That results at least in unexpected short times.

U8g libs do not mess with the watchdog. Neither they activate the watchdog, nor do they reset the watchdog for you. However. U8g operations take time. The shortest watchdog times may be exceeded (WDTO_30MS) on slow processors/displays/transfer-methods.

AnHardt commented 5 years ago

Sorry was from memory. The 4 bits are in the same register but not consecutive. -> same result.