I am using an Arduino UNO board as an ISP to program a target ATmega328P (technically mounted on an Arduino Nano board). There are no issues compiling the code or converting it to ihex, but sometimes there are problems programming the target with avrdude
.
The 'Arduino as ISP' UNO-board (programmer) is connected to my PC at COM6. Its SPI interface is connected to the Arduino Nano board (ATmega328P/Target) with jumper cables. The 'target' board is powered separately from the 'programmer' but the two boards share GND.
I am using WSL to work, so the serial port COM6 in windows corresponds to the linux port /dev/ttyS6
. After successfully compiling, linking and converting the program I am attempting to program the target using:
$ avrdude -v -C /etc/avrdude.conf -p atmega328p -c stk500v1 -P /dev/ttyS6 -b 19200 -U flash:w:my_program.hex:i
but I get the very common error saying
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x15 avrdude: stk500_recv(): programmer is not responding
Here's the kicker: If i instead use the Arduino IDE to upload just an example blink sketch by pressing 'Upload Using Programmer' it works without any issues.
Thereafter I can use avrdude from WSL - the exact same command as earlier - and it works! It works until I unplug the programmer and then plugs it back in, that is. Then I have to use the Arduino IDE to once again upload an example sketch before being able to program the target from WSL.
Does anyone have experience with this, or have any clue as to what may fix my problem?
Short version:
I am using Arduino as ISP to program ATmega328P target from WSL.
Programming target with avrdude from WSL command line gives "programmer not in sync" error.
When programming target with the ISP via the Arduino IDE there are no problems.
After doing that once, programming the target with avrdude from WSL works without issues, until I unplug the programmer.
UPDATE:
I tried running avrdude from Windows via PowerShell. This had the same effect as using 'Upload Using Programmer' through Arduino IDE.
So I tried another machine altogether, running Ubuntu. What do you know, it works perfectly!
This leads me to conclude that this is a WSL-issue, and thereby its relevance in this forum fading. Still, if someone has any experience with avrdude on WSL or maybe just serial ports in general on WSL, any help is greatly appreciated. Otherwise this post can be closed.