Skip to main content

USB to Serial Converter using AVR microcontrollers

AVR-CDC converts USB and RS-232C signals using the AVR micro- controller which has no on-chip USB interface. This technology is based on Object Deveopment's V-USB (Software-USB on AVR), and the CDC (Communication Device Class) protocol was extended over it. AVR-CDC enables PC to communicate with the USB device through virtual COM port.
The basic idea of using CDC protocol over Low-speed USB is based on Kyosuke Ishikawa's experiment in 2005. To make it stable and practical, Christian Starkjohann in Object Development helped me modifying his V-USB stack. Since three endpoints and the bulk transfer on low-speed device violates the USB standard, I added a tiny patch driver on Windows' USB stack.
Although this technology is quite experimental, it may be useful to interface your original system to PC easily. The circuit is very simple, but it requires a certain amount of skills to control. If you need practical or stable solutions, or you are not familiar with electronics nor installing drivers, use the dedicated chip from vendors like FTDI.
The back door to the low-speed bulk transfer is gradually closing on the newer OS. After enjoying this USB technology, switch to the HID protocol or to MCU having on-chip USB controller.

CDC-232 creates a virtual COM port on PC that doesn't have real RS- 232C port. It enables RS-232C communication (without control lines), after connecting the device and installing the driver.

Virtual COM Port over Software-USB

Write the program to AVR, build the circuit, and connect the device to PC's USB port. Install the driver on Windows. Access the device through generated virtual COM port from terminal software or your application. Control lines (DTR, DTS, RTS, CTS) are not used by the host application. Set the terminal software as "no flow-control".
Windows requests the driver installation again when connected to other USB port. Detect the previously installed driver automatically. Another COM number will be assigned. If you set serial number in AVR (rebuild with modified usbconfig.h), you can get the same COM port at any USB port. However, you cannot connect multiple CDC devices of the same serial number.
Before detaching the device, close the COM port in terminal software or in your application. Otherwise, you cannot connect to the device again because of the broken file handle. Restart the terminal software or your application then. Switch to the fast transfer mode using "lowcdc.vbs" to get the baudrate higher than 9600bps.

Loop-back test on ATtiny45 version
These schematics are for ATtiny45/85, ATtiny2313/AT90S2313, and ATmega8/48/88/168. Their firmware are all ISP-programmable. The red LED drops the USB voltage from 5V to 3.3V, and provides to AVR. The current is about 10mA, and is not enough to drive other circuit. When connecting to other MCU, connect Gnd and connect TxD and RxD in crossing way. R4 limits the leak current when the MCU's Vcc is 5V. You can omit if the Vcc is equal. R5 protects the TxD pin when it shortened to Gnd. You can omit both R4 and R5 if you connect to the RS- 232C driver like MAX232. Use crystal oscillator. Although ceramic resonator works well in most cases, it becomes unstable if the frequency deviation is bigger. 

 CDC-232 for ATtiny45-20
ATtiny45/85 uses internal RC oscillator and PLL. It is calibrated by  USB signal when connected. UART is implemented by software. It is not enough for high speed data transfer. If the TxD and the RxD are inverted (rebuild with -DUART_INVERT option), you can directly connect to RS-232C line.     1200 - 4800bps, 8N1

CDC-232 for ATtiny2313-20               

ATtiny2313/AT90S2313 has 2KB program memory. Although the baudrate is configured automatically, some functions are omitted.   600 - 38400bps, 8N1

CDC-232 for ATmega8/48/88-20
ATmega8/48/88's internal UART is configured from the PC. The flow-control (RTS/CTS) is supported.
600 - 38400bps, data 7/8, parity N/E/O, stop 1/2


 CDC-232 for ATtiny45-20

CDC-232 for ATtiny2313-20


CDC-232 for ATmega8/48/88-20

Driver and code click here for CDC home page

Popular posts from this blog

PIC Microcontroller Based Electronic Lock

Circuit Diagram

Security is a prime concern in our day-today life. Everyone wants to be as much secure as possible. An access control for doors forms a vital link in a security chain. The microcontroller based digital lock for Doors is an access control system that allows only authorized persons to access a restricted area. An electronic lock or digital lock is a device which has an electronic control assembly attached to it. They are provided with an access control system. This system allows the user to unlock the device with a password. The password is entered by making use of a keypad. The user can also set his password to ensure better protection. The major components include a Keypad, LCD and the controller PIC16F877A. This article describes the making of an electronic code lock using the 16F877A microcontroller.
The system is fully controlled by the 8 bit microcontroller 16F877A which has a 8Kbytes of ROM for the program memory. The password is stored in the EPROM so that we …

PIC Serial Communication Tutorial (UART)

First, a quick history of RS232. What is RS232? It's just a name for a standard that has propagated from generation to generation of computers. The first computers had serial ports that used RS232, and even current computers have serial ports (or at least USB ports that act like RS232 ports). Back in the day, serial information needed to be passed from devices like printers, joysticks, scanners, etc to the computer. The simplest way to do this was to pass a series of 1s and 0s to the computer. Both the computer and the device agreed on a speed of information - 'bits per second'. A computer would pass image data to a printer at 9600 bits per second and the printer would listen for this stream of 1s and 0s expecting a new bit every 1/9600 = 104us (104 micro-seconds, 0.000104 seconds). As long as the computer output bits at the pre-determined speed, the printer could listen.
Zoom forward to today. Electronics have changed a bit. Before they were relatively high power, high …