B4R Question watchdog in B4r

MbedAndroid

Active Member
Licensed User
Longtime User
Most applications uses a wathdog.
In avr/arduino this is a buildin timer
I made small inline C code which init the watchdog, and resets the watchdog.
So far so good. But for test i dont give a resetwatchdog, thus the watchdog fires.
Then something happens which is not normal
The arduino comes in a kind of loop, see the LED flashing fast, and it isnt possible to load new application.

anyone knows why? The arduino should reboot, but hangs in some loop. Even pressing the resetswitch doesnt work.
B4X:
#if C

#include <avr/wdt.h>
void WatchdogInit (B4R::Object* o) {
   wdt_enable (WDTO_2S);
}   
void WatchdogReset (B4R::Object* o) {
wdt_reset ();
}
void wdt_disable (B4R::Object* o) {
wdt_disable() ;
}
#End if

calling the init is like:
B4X:
RunNative("WatchdogInit", Null)
calling the reset is line
B4X:
RunNative("WatchdogReset", Null)
 

MbedAndroid

Active Member
Licensed User
Longtime User
that isnt a watchdog application
A watchdog should become active when the program beconme nuts in some undefined loop

Anyway
i tried this optiboot loader, doesnt work with B4R
Then i tried a small program in visual studio, there also i cant use the watchdog. the board simply doesnt reboot
need to check the schematic why also the reset button doesnt work in a C# program
 
Upvote 0

MbedAndroid

Active Member
Licensed User
Longtime User
should it be possible to intercept the watchdog ISR? What will happen when i insert inline C with the watchdog ISR vector?
Are global interrupts enabled in B4R? (sei())
 
Upvote 0

MbedAndroid

Active Member
Licensed User
Longtime User
this inline code works perfect -for the moment-
reset the arduino without hanging
no need for optiboot loader
B4X:
#if C
ISR(WDT_vect)
{
asm volatile ("  jmp 0");
}

#include <avr/wdt.h>
void WatchdogInit (B4R::Object* o) {

wdt_enable(WDTO_8S );
cli();
WDTCSR =(1<<WDIE);
sei();  // Enable the Interrupts
}  

void WatchdogReset (B4R::Object* o) {
wdt_reset ();
}

void wdt_disable (B4R::Object* o) {
wdt_disable() ;
}
#End if
 
Last edited:
Upvote 0

peng250

New Member
Hi,I added your code to my Arduino side program, but compiler gets error. How I can add it correctly?
B4X:
#include <Stepper.h>
int c1 = 9;
int c2 = 10;
int c3 = 11;
int c4 = 12;

int Pulse;
int Speed;

Stepper motor(200, c1, c2, c3, c4);

void setup() {
  pinMode(c1, OUTPUT);
  pinMode(c2, OUTPUT);
  pinMode(c3, OUTPUT);
  pinMode(c4, OUTPUT);
while(!Serial);
 Serial.begin(9600);
}

void loop() {
  if (Serial.available())
  {
    Pulse = Serial.parseInt();
    Speed = Serial.parseInt();
    
     motor.setSpeed(Speed);
     motor.step(Pulse);
     delay(0.5);
      
  }
 
}
 
Upvote 0
Top