The serial programmer you are using is using serial port to connect to computer, but not the standard RS232 protocol! Take a closer look at the schematic:
- pin 4 (DTR) is assigned to MOSI. On a true motherboard serial port this pin can be toggled high and low, thus emulating a bitbang mode
- pin 6 (DSR) and 7 (RTS) are asigned to SCK. As DTR, RTS can be set either high or low, thus along with DTR allowing software implementation of custom synchronous serial protocols
- pin 8 (CTS) is an input pin assigned to MOSI. Its value is read on SCK toggle.
DTR and RTS are the only pins of the serial port that can be bitbanged. But there is the need for a reset signal. The designer of that adapter uses a trick. He sends a 0x00 character with no stop bits over standard RS232 TX, thus creating a short reset pulse (which for some MCUs need to be inverted).
The actual data on a standard serial RS232 communication is actually sent only via Rx/Tx lines. All the others are accessory lines used by devices to signal different states of operation or to signal data availability or transfer termination.
This is the problem with USB-serial adapters. Most of them can only use Rx/Tx lines and of course, only serial RS232 (asynchronous) protocol, which is by no means compatible with AVR programming protocol (SPI, synchronous). So the only way to communicate via serial port by SPI is to use alternate lines and emulate the protocol in software.
You can see on this forum that in some cases it works with USB-serial adapters, but in most situations it doesn't.
I thought most or all of the microcontroller of ATmega series microcontrollers are without usb support.
What do you say about: ATmega 8U2, 16U2, 16U4, 32U2, AT90USB1286, AT90USB1287, AT90USB162, AT90USB646, AT90USB647, AT90USB82. Full list from here.
But USBasp is not using one of those MCUs! Looking at its schematic we can see that it uses a pull-up resistor on the D- line, which means it signals the PC that it is a low speed device (1.5 Mb/s). And it software emulates USB bus over a general use I/O port (can be seen in AVR firmware source code - file usbconfig.h
):
#define USB_CFG_IOPORTNAME B
/* This is the port where the USB bus is connected. When you configure it to
* "B", the registers PORTB, PINB and DDRB will be used.
*/
#define USB_CFG_DMINUS_BIT 0
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
* This may be any bit in the port.
*/
#define USB_CFG_DPLUS_BIT 1
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
* This may be any bit in the port. Please note that D+ must also be connected
* to interrupt pin INT0!
*/
#define USB_CFG_CLOCK_KHZ 12000
/* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
* The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
* deviation from the nominal frequency. All other rates require a precision
* of 2000 ppm and thus a crystal!
* Default if not specified: 12 MHz
*/
The bootloader should exit and run the user program after 6 seconds if USB is not connected. If that is too slow then you can recompile with a shorter delay, or set AUTO_EXIT_NO_USB_MS >1.
If the user program doesn't appear to be running after the timeout period then you probably have some other problem. Perhaps your program has a bug that stops it from working properly if the bootloader doesn't communicate with the USB port first (check for uninitialized variables, hardware registers not being set to defined states etc.).
Also, if the board is powered by the USB port when plugged into it then make sure that your external power supply is good enough to run it stand-alone.
(in bootloaderconfig.h)
/*
* Define bootloader timeout value.
*
* The bootloader will only time out if a user program was loaded.
*
* AUTO_EXIT_NO_USB_MS The bootloader will exit after this delay if no USB is connected.
* Set to 0 to disable
* Adds ~6 bytes.
* (This will wait for an USB SE0 reset from the host)
*
* AUTO_EXIT_MS The bootloader will exit after this delay if no USB communication
* from the host tool was received.
* Set to 0 to disable
*
* All values are approx. in milliseconds
*/
#define AUTO_EXIT_NO_USB_MS 0
#define AUTO_EXIT_MS 5000
/*
Best Answer
Having bought several of these units from several sources:
They are typically pre-programmed, and should work out of the box with the Arduino IDE. I have not yet come across one that doesn't have the USB bootloader.
However, because they come from so many suppliers, this may not always be the case. In which case, you should get yourself an AVR ISP programmer (they are very cheap), which can program any ATtiny or ATmega.