United Kingdom
Offline
Faraday Member
Karma: 131
Posts: 4681
|
 |
« Reply #15 on: November 07, 2012, 06:23:57 am » |
Have you tried disabling the watchdog at the start of setup(), using the code I gave in the thread I linked to in an earlier post?
|
|
|
|
|
Logged
|
Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #16 on: November 07, 2012, 07:17:38 am » |
Yes, I do (see the code below).  I must confess you that there is something that escapes me. Indifferently of boot, if I write in the watchdog registers the good values, the µP must be done a reset. Why doesn't it done ? #include <avr/wdt.h>
void setup() { Serial.begin(9600);
// Turn off watchdog timer <--- recopy to your post cli(); wdt_reset(); MCUSR = 0; // clear watchdog reset flag WDTCSR |= (1 << WDCE) | (1 << WDE); WDTCSR = 0x00; sei(); // set the watchdog to 8s wdt_reset(); // disable all interrupts cli(); wdt_reset(); MCUSR &= ~(1<<WDRF); WDTCSR |= (1 << WDCE) | (1 << WDE); WDTCSR = (1 << WDE) | (1 << WDP3) | (1 << WDP2) | (1 << WDP1) | (1 << WDP0); // 8s // enable all interrupts sei(); } void loop() { Serial.println("I am in the loop"); while(1) { // to have the reset !!! Serial.println(millis()); } }
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #17 on: November 08, 2012, 04:35:38 pm » |
Sorry for my insistence, but I am always blocking  Is there any body who arrive to do worked a reset watchog on arduino mega ? If yes, please could you give me a simple example. Thanks in advance.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #18 on: November 09, 2012, 01:20:11 am » |
What's all the mucking around with registers? Here is an example that works on a Uno: #include <avr/wdt.h>
void setup () { Serial.begin (115200); wdt_enable(WDTO_1S); // reset after one second, if no "pat the dog" received } // end of setup
void loop () { Serial.println ("Entered loop ..."); Serial.println ("Point A"); delay (500); Serial.println ("Point B"); delay (400); wdt_reset(); // give me another second to do stuff (pat the dog) Serial.println ("Point C"); delay (500); Serial.println ("Point D"); delay (400); while (true) ; // ohno!, went into a loop } // end of loop
I tested that on my Mega and it didn't work. I suspect there is a problem with the bootloader and then watchdog timer. There are some known problems with the watchdog timer and the bootloader.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #19 on: November 09, 2012, 01:47:26 am » |
That sketch bricks my Mega in a rather annoying way. You can recover by re-uploading the bootloader but there is clearly something wrong. You can also recover by: - Open a sketch that doesn't use the watchdog (eg. Blink)
- Unplug the USB (so the board is powered off)
- Hold down the reset button with one hand
- Keeping it held down, plug in the USB
- Start uploading
- Release the reset button a moment or two after it says "uploading"
- With luck, the new sketch will be uploaded
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #20 on: November 09, 2012, 02:13:12 am » |
I uploaded the above sketch to my Mega and unset the BOOTRST fuse (so it skips the bootloader). With the sketch starting directly, I see: Entered setup ... Entered loop ... Point A Point B Point C Point D Entered setup ... Entered loop ... Point A Point B Point C Point D Entered setup ... Entered loop ... Point A Point B Point C Point D Entered setup ... Entered loop ... Point A Point B Point C Point D Entered setup ... Entered loop ... Point A Point B Point C Point D Entered setup ... Entered loop ... Point A Point B Point C Point D Entered setup ... Entered loop ... Point A Point B Point C Point D
So the watchdog works then. 
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #21 on: November 09, 2012, 08:08:56 am » |
 I am happy to see that the watchdog can work with mega board. I followed each step that you said but the program stops after "Point D". I think that my problem is with BOOTRST fuse. I uploaded the above sketch to my Mega and unset the BOOTRST fuse (so it skips the bootloader). With the sketch starting directly, I see: I didn't find where I can unset the BOOTRST fuse. How do you do that ? Thanks very much for your help.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #22 on: November 09, 2012, 02:55:22 pm » |
I uploaded the .hex file with my "hex file uploader" described here: http://www.gammon.com.au/forum/?id=11638A side-effect is it clears the BOOTRST fuse if it is uploading a "normal" program (not a bootloader). However if you have a programmer (such as USBISP or similar) you can use avrdude to change fuses. Something like this: avrdude -c usbtiny -p m2560 -U hfuse:w:0xD9:m
Better check with http://www.engbedded.com/fusecalc before changing fuses. Get that wrong and you might not be able to program it again without using a high-voltage programmer (next to impossible with a surface-mounted chip). The alternative is to ask around for a bootloader that doesn't have this problem. I thought mine didn't but was wrong. You still need a programmer to install the new bootloader, but you can use a spare Uno for that. (See the posts about Arduino as ISP).
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #23 on: November 10, 2012, 04:14:35 am » |
Thank you very much for your answer and a big cheer for your project, it is very interesting. Actually, I haven't the equipment to work the reset watchdog on arduino mega. I keep this post and I will buy the programmer or a SD card reader to use your project with my uno.  A last idea comes me, does it exist an other board with equivalent ATMEL as mega, which the reset watchdog works with the default bootloader ?
|
|
|
|
|
Logged
|
|
|
|
|
United Kingdom
Offline
Faraday Member
Karma: 131
Posts: 4681
|
 |
« Reply #24 on: November 10, 2012, 04:22:05 am » |
A quick google for 'arduino mega bootloader watchdog' came up with some alternative bootloaders.
|
|
|
|
|
Logged
|
Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #25 on: November 10, 2012, 05:27:25 am » |
yes, I already saw that, but I don't have equipment to flash my board. So, I will buy the programmer and as well as placing an order, I want to know, if it exists a board equivalent to arduino mega which the reset watchdog works by default (with factory parameters). Do you know if is it exist ?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #26 on: November 10, 2012, 03:21:23 pm » |
The bootloader is software. It's easy enough to replace it. Personally I don't know of a Mega-equivalent with the correct bootloader on it. A quick google for 'arduino mega bootloader watchdog' came up with some alternative bootloaders. Yes, well I downloaded one that claimed to have fixed the watchdog problem, but it didn't.
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #27 on: November 11, 2012, 09:50:16 am » |
Thanks for your answer, I bought the programmer and I hate to receive it to flash the bootloader.
|
|
|
|
|
Logged
|
|
|
|
|
|