After wasting like 10 hours trying to get the USBtinyISP programmer recognized by avrdude, I thought to write about it to help others in the same situation. At first I thought is something Linux related but same error message appeared on Windows. All online advises related to this issue where around udev rules and permissions but in my case it turned out to be avrdude the culprit. The error message was: avrdude usbtiny_open() error: cannot find USBtiny device (0x403/0x6015).
Contents
Setting up USBTinyISP
Windows
On Windows you need to install the drivers provided by Adafruit here: https://learn.adafruit.com/usbtinyisp/drivers.
Linux
On Linux you don't need to install anything but you need to be part of the dialout group to access USB devices without superuser privileges.
The dialout group in Linux is used to grant users permission to access
serial ports, which is often necessary for tasks like programming
microcontrollers. Users added to this group can communicate with devices
connected via USB or serial interfaces without needing superuser privileges.
To add yourself to dialout group, open a terminal using CTRL+ALT+T and use the following command then restart the computer:
sudo usermod -aG dialout $(whoami)
Use the groups command if you wish to confirm you belong to
dialout group.
Adding udev rule is not necessary since avrdude already has the necessary rules in /usr/lib/udev/rules.d folder in the 60-avrdude.rules file.
To see the rules use:
gedit /usr/lib/udev/rules.d/60-avrdude.rules
The rule for USBTinyISP is:
SUBSYSTEM=="usb", ATTR{idVendor}=="1781", ATTR{idProduct}=="0c9f", TAG+="uaccess"
Notice the idVendor and idProduct attributes. Those must match your programming device to be able to use it. Just in case it doesn't I'll show how to add a custom udev rule.
Adding custom udev rule
To add a custom udev rule named usbtiny.rules use following command with sudo meaning superuser privileges. Name of the file is not important.
sudo gedit /etc/udev/rules.d/usbtiny.rules
In the gedit editor add:
SUBSYSTEMS=="usb", ATTRS{idProduct}=="0c9f", ATTRS{idVendor}=="1781", GROUP="dialout", TAG+="uaccess"
Replace idProduct and idVendor to match your device. To find product and vendor IDs, unplug the usb cable from USBtiny then plug it back in, then in another terminal (CTRL+ALT+T) use dmesg -T to see kernel logs with human readable timestamps. It should look something like this:
new low-speed USB device number 6 using xhci_hcd
usb 1-9: New USB
device found, idVendor=1781, idProduct=0c9f, bcdDevice=
1.04
usb 1-9: New USB device strings: Mfr=0, Product=2,
SerialNumber=0
usb 1-9: Product: USBtiny
Finally press CTRL+S to save the udev rule file then ALT+F4 to close it. To confirm file creation, use:
ls /etc/udev/rules.d
You now should see the file usbtiny.rules. Last steps is to reload the rules then unplug and plug the device:
sudo udevadm control --reload-rules && sudo udevadm trigger
Installing avrdude
On Windows the executable can be downloaded here: https://github.com/avrdudes/avrdude/releases. For most users the version to download is avrdude-v8.0-windows-x64.zip. This is a stand-alone application so just unzip the folder in a location of your choice. You can then add the folder location to PATH to be able to invoke avrdude from the terminal directly simply using avrdude.exe without the need to specify the full path to it.
On Linux use:
sudo apt-get install avrdude
to install avrdude.
Testing USBtinyISP
It is a good idea to test the USBtiny device first, before connecting it to a microcontroller. This can be done using:
avrdude -c usbtiny -p m324pb -v -P usb
-c specifies the programmer type, in this case usbtiny.
-p is the microcontroller, here using atmega324PB but the short hand is m324pb. At this point it doesn't matter as long as it is a valid value since we only want to see if the USBtiny device is recognized by avrdude.
-P must be usb since this is not showing up as a ttyUSB* or COM* like with an FTDI programmer.
-v is verbose mode
If you see avrdude: usbdev_open(): found USBtinyISP somewhere, then the device works. If the message shows that it cannot find USBtiny device, then see a solution down below.
Possible USBtinyISP issues
Green led off
Many times I experienced the following issue both on Windows and Linux, that sometimes after plugging in, the green led is off and the device doesn't work. If after another plug out and back in the problem persist, my solution is to take something with large area made out of metal and to rub across the solder joints making sure every connection is shorted. Of course with the device unplugged. After that it works every time. Don't know why.
Cannot find device
Another hard to find solution was this error message from avrdude after using
avrdude -c usbtiny -p m324pb -v -P usb:
avrdude usbtiny_open() error: cannot find USBtiny device (0x403/0x6015)
To fix this issue we need to add the programmer in the avrdude configuration file.
On Windows in the stand-alone application, the avrdude.conf file is in the same folder as avrdude.exe.
On Linux the location can be found by running the above command that has the -v (verbose) flag. Then you can see the file paths for the system wide configuration as well as user configuration. It is recommended to use the user configuration or create one if doesn't exist at the specified location.
To create or edit the configuration file use:
gedit /home/$(whoami)/.avrduderc
and paste
programmer
id
= "usbtinyisp";
desc
= "USBtiny simple USB programmer, https://learn.adafruit.com/usbtinyisp";
type
= "usbtiny";
prog_modes
= PM_TPI | PM_ISP;
connection_type = usb;
usbvid
= 0x1781;
usbpid
= 0x0c9f;
;
Then save and close the file.
As described above, the vid and pid can be found by using the dmesg -T command just after plugging in the device. The type must be usbtiny and the id can be anything but should not be in the system wide configuration. I have used usbtinyisp.
To check the system wide configuration file, use:
gedit /etc/avrdude.conf
The original configuration for usbtiny programmer is:
programmer
id
= "usbtiny";
desc
= "USBtiny simple USB programmer, https://learn.adafruit.com/usbtinyisp";
type
= "usbtiny";
prog_modes
= PM_TPI | PM_ISP;
connection_type = usb;
usbvid
= 0x0403;
usbpid
= 0x6015;
;
Now the values 0x403/0x6015 in the error message make more sense.
Turns out, there is a programmer with 0x1781 and 0x0c9f in avrdude system configuration, named adafruit_gemma, and you can use that if you prefer.
Now running the command:
avrdude -c usbtinyisp -p m324pb -v -P usb
should display avrdude: usbdev_open(): found USBtinyISP.
Device signature 0x00
This error indicates that USBtiny cannot read the microcontroller. This could be caused by many things.
Check wire connections for continuity from each solder joint pin of the programmer to the microcontroller pin, especially if it was hand soldered and the pin was not soldered properly. Also the flat cable connectors can sometimes be mirrored in one or two axes. Use a multimeter in continuity mode to check for this.
Another rare case is when using a microcontroller from another project and the fuse is set to use an external crystal and current project is using the internal RC oscillator and without an external crystal the microcontroller cannot work. Without a high voltage programmer, you need to solder somehow a crystal and two capacitors to be able to change the fuses using an ISP programmer. I have done this because I had some big footprints connected to the XTAL pins few centimeters away. The long distance caused errors after each fuse type but after each fuse (low, high, extended) was successfully written was removed from command for the others to have more chances. Or just use a new one.
Power supply
The programmer can supply 5V to programmed board if the jumper is present so make sure the board is 5V tolerant and it doesn't have another power source on. Remove the jumper when using an external power supply.
No comments:
Post a Comment