328p and wdt without using the bootloader

I am using a 328p programmed with a usbtinyisp. So there is no bootloader. avr/wdt.h was working fine when I had both the bootloader and the program. However, it does not work in the same program without the bootloader. I assume it is just restarting at the wrong address.

Can the start address for the avr/wdt be set to 0 somehow?

Any other solutions? I did see this one with a different wdt which I may use. using watchdog without any bootloader.

The restart address is always 0. If a bootloader is present, it takes over this address, then at some point, jumps to the start of the Arduino program. Note: this depends on the setting of the BOOTRST fuse. See the data sheet, and check whether that fuse is set.

There is something wrong with your approach if the WDT does not successfully reset and restart a program uploaded using the ISP "no bootloader" method.

If you wish forum members to help, post the code and relevant details.

I have a few 328p's running with the WDT enabled. However I've programmed them with the omniboot bootloader.

It seems there is a race condition with the standard bootloader where the WDT times out before the timer reset.

I say this because I don't know your program or how it starts up. Perhaps the WDT needs to be reset earlier in the program.

Good news. Building on the following thread, in setup, I changed the first line from wdt disable (with a later wdt enable before the loop) to a single wdt enable with 2s. This fixed it. Still odd that the original code did work when a bootloader was also installed.

I thought I was kind of familiar with WDT behavior, but not anymore.

Do you have WDTON fuse bit programmed?

That would be the only explanation I have. Because in that case the state of WDTCSR (which was reset to 0 according to @westfw's post) doesn't matter (?) and WDT is always in System reset mode. When you changed the first line in setup to set 2s timeout, you prevented/"postponed" the already running 16ms timeout (?).

Very interesting. I will look into how I can read them with the USBtinyISP and post results. Likely will take a few days.

A simple avrdude command:


avrdude -c usbtiny -p m328P -v

Is there a way to send this in the Arduino ide, or do I have to download avrdude for windows10 and then use the windows command line?

I know it's doable by loading the sketch hex file directly to the chip through the ICSP pins. The bootloader is a hex file loaded the same way that loads your sketch hex file on top of itself through serial.

30 minutes of sifting through old docs to find what's easy, too many pages for my eyes after a while. It is one choice and IIRC knowing where the IDE put the hex file difficulty.

Avrdude is already on your computer. The IDE invokes it with command line arguments when uploading a sketch.

Well I have searched and searched. How do I actually send this command?

I tried entering this command in the windows command line from the directory containing avrdude.conf to no avail.

I have searched and searched. How do I actually send this command?

If you turn on the "verbose" preferences for upload, and try to upload a sketch, you will see the command that the IDE is issuing on your behalf (actually, it's likely to scroll by pretty quickly, so you might have to hunt for it a bit.)

It'll look something like this:

C:\Users\billw\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\billw\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -carduino -PCOM3 -b115200 -D -Uflash:w:C:\Users\billw\AppData\Local\Temp\arduino_build_434767/myBlink.ino.hex:i 

Just copy the beginning part of that, up through the parts that aren't specific to what you're trying to do, and add the new commands at the end.

C:\Users\billw\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\billw\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf    -c usbtiny -p m328P -v  

so I look at this example on avrdude...

Will this ICSP a hex file over the bootloader given COM1 and hex file path and name are correct?

avrdude -c arduino -P COM1 -b 115200 -p atmega328p -D -U flash:w:objs/my.hex:i

It looks right. It might need the -C option to specify the location of its config file, because the arduino version seems to have been built a bit weird:

 ~/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -carduino -P /dev/tty.usbserial-A20e1Kh4 -b115200 -t -patmega328p
avrdude: can't open config file "/Users/jenkins/jenkins/workspace/avrdude-staging/label/mac-mini/objdir/etc/avrdude.conf": No such file or directory
avrdude: error reading system wide configuration file "/Users/jenkins/jenkins/workspace/avrdude-staging/label/mac-mini/objdir/etc/avrdude.conf"

If I cd to the hex file directory, the hex file will be on my path.

IIRC, I should be able to set the default hex file destination folder.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.