Electronic – Why usb to serial port converter can’t program avr microcontroller

atmegaavrserialusb

With a serial port or parallel port in pc programming avr microcontroller is very easy and cheap. Problem is, no modern computer come with serial or parallel port. So, usb to serial converter should be the solution but unfortunately not.

There must be a difference between the actual serial port and converted serial port. What is it?

Another related question would be, how USBasp communicate almost directly with pc? I thought most or all of the microcontroller of ATmega series microcontrollers are without usb support.

I have checked this link-
AVR programmer with serial to USB converter

I know there are several question like this but being new to embedded programming I need an easy explanation to get the concept. Thanks.

Edit:
I want to use a circuit as below with the converted serial (possibly, RS232) interface.This circuit is designed for actual serial port.With a converted serial port, I might be able to reduce some complexity of the circuit.
Schematic of the serial programmer

The detail can be found at Simple Serial Programmer for AVR

Best Answer

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
 */