1

I am using Arduino DUE in my project. The project is massive (about 7000 lines of code in total, with massive schematic), so I decided not to post the whole code and schematic, except explain the hardware and configuration I am working with:

  • Arduino DUE;
  • 12V switching power supply;
  • LTC1660 DAC (used withstandard SPI library);
  • Nextion HMI (Used with standard library #include Nextion.h //INCLUDE NEXTION LIBRARY);
  • DS3231 RTC module on I2C bus (Library used: Wire #include <DS3231.h>)
  • 24LC256 EEPROM on same I2C bus (Library used: Ext EEPROM #include <extEEPROM.h>)

The base line, is that on power-on the controller just freezes besides, it can't be the problem with power as I get this problem using both 12 V from switching PSU and 5 V USB cable. I can not really analyse the problem, as the deadlock occurs even before the program start to execute content of void setup(). My best guess is that the deadlock occurs due to infinite loops in the Arduino's twi.cpp where infinite loop can occur if the controller receives no acknowledge bit. But then again I can not be sure here. However when I push restart button on the Arduino or enable Serial monitor in Arduino IDE when the circuit is powered on , it starts to work, and it works just as expected.

After reading the datasheet for the DUE's μC, I've found that it have the watchdog option embedded:

After a Processor Reset, the value of WDV is 0xFFF, corresponding to the maximum value of the counter with the external reset generation enabled (field WDRSTEN at 1 after a Backup Reset). This means that a default Watchdog is running at reset, i.e., at power-up. The user must either disable it (by setting the WDDIS bit in WDT_MR) if he does not expect to use it or must reprogram it to meet the maximum Watchdog period the application requires. The Watchdog Mode Register (WDT_MR) can be written only once. Only a processor reset resets it. Writing the WDT_MR register reloads the timer with the newly programmed mode parameters.

I've started to explore it, and as I got it, the watchdog is ON by default, and its timer period is 16 seconds by default, so as it is not normally used in DUE, I assumed, that somewhere it is just disabled, and in main.cpp I found the following:

int main( void )
{
   // Initialize watchdog
   watchdogSetup();
   init();
   initVariant();

where watchdogSetup() led to:

void watchdogDisable(void)
{
   WDT_Disable (WDT);
}
void watchdogReset(void)
{
   WDT_Restart (WDT);
}
extern "C"
void _watchdogDefaultSetup (void)
{
   WDT_Disable (WDT);
}
void watchdogSetup (void) __attribute__ ((weak, alias("_watchdogDefaultSetup")));

As I got it, due to this, the watchdog was disabled for DUE by default, and commenting out watchdogSetup(); in int main() would allow the watchdog to work (as watchdog is on at power on by default, according to datasheet).

I've also added the WDT_Restart (WDT); to void loop() of the program in order to kick watchdog every program cycle.

Well, for some reason, that did not help me, and I'm still receiving the deadlock when I power on the controller, even through the watchdog is technically not disabled, after 16 seconds it still do not restart the system. And, pressing the reset button or the Serial monitor in Arduino IDE makes the system run as expected. Am I missing something out? Your help and suggestions are appreciated, shall any additional info be needed, just let me know, I need to get this project running so badly.

By the way, my void setup() function is quite long, and if I set the watchdog to 1 second, using void watchdogEnable (uint32_t timeout) instead of commenting out watchdogSetup() in main.cpp, and use reset button after power on, I can see the watchdog working as it can't get to void loop() in time in order to reset watchdog (as void setup() takes about 3 seconds due to delays).

migrated from electronics.stackexchange.com Nov 26 '16 at 22:47

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • 1
    Do you know what the purpose of the weak attribute is? – Majenko Nov 26 '16 at 23:16
  • You don't need to comment out the Arduino core source code. Just add the watchdogSetup function to your own code. Try creating a simple sketch first to make sure you get the WDT to work properly before adding it to your existing code – Gerben Nov 27 '16 at 8:05
  • @Majenko, no I dont know what the meaning of the attribute is, can you explain ? – Svjatoslavs Krasnikovs Nov 27 '16 at 9:04
  • @Gerben, you see, the problem is that the deadlock occure even before the content if void setup() is executed. – Svjatoslavs Krasnikovs Nov 27 '16 at 9:04
  • @SlavaKrasnikov - I believe you have misidentified the cause. The watchdog (in the state set by the default s/w init code) is disabled (as highlighted by Majenko). Don't complicate your problem by enabling the watchdog! Your original code, with default watchdog configuration, executes the same instructions whether it is starting from a power-on reset, or pressing the rest button, yet the latter "works", which confirms default watchdog config works OK. Previously I saw similar behaviour due to various h/w design issues, but testing your h/w would need more help than fits into a comment. :-( – SamGibson Nov 27 '16 at 14:51
0

Found people suffering with the same problem on Arduino's official forum. It turned out that the problem arises from the schematic of Arduino Due, that fails to hold 'reset' pin high for long enough period of time on power-on.

There are multiple solutions involving adding some capacitance between reset pin and ground pin, but this might damage circuit in long run (at power-off), so I managed to find other way around it: there is an ATmega16U2 used as USE-to-TLL serial chip that have access to reset pin of AT91SAM3X8E.

The ATmega16u2 can be reprogrammed so that on power-on it provide short "HIGH" period to AT91SAM3X8E reset pin. The program for ATmega16U2 can be found here: https://forum.arduino.cc/index.php?action=dlattach;topic=167492.0;attach=52901

The updating precision is given here: https://www.arduino.cc/en/Hacking/Upgrading16U2Due

I've performed the given precision using Arduino UNO as programmer and can confirm that it worked properly.The problem's gone now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.