The Universal Serial Bus (USB) interface has gained immense popularity due to its user-friendly applications, allowing for Plug and Play functionality without the need for system restarts. However, for developers, integrating USB into end systems has proven to be more complex compared to alternatives such as RS232. Additionally, device drivers are required for software support on the PC side. Consequently, RS232 communication remains widely used among end system manufacturers. This interface is well established and benefits from strong operating system support; however, the physical RS232 port has recently been removed from standard PC interfaces, giving way to USB ports. USB implementation in external devices can be approached in two ways: 1. Utilizing a microcontroller with a hardware-implemented USB interface. This requires an understanding of USB operation and the development of firmware for the microcontroller. It is also necessary to create a driver on the computer side unless the operating system includes standard USB classes. A significant drawback is the limited availability and higher cost of such microcontrollers compared to simpler RS232 microcontrollers. 2. The alternative is to employ a universal converter between USB and another interface, typically RS232, an 8-bit data bus, or TWI bus. This approach eliminates the need for special firmware or in-depth USB knowledge, as the converter vendor typically provides a single driver for the entire solution. However, this option tends to be more expensive and results in a larger overall product size. The solution presented in this document describes a USB implementation using a low-cost microcontroller that emulates the USB protocol within the firmware. The primary challenge of this design is achieving adequate speed, as the USB bus operates at various speeds: LowSpeed at 1.5 Mbit/s, FullSpeed at 12 Mbit/s, and HighSpeed at 480 Mbit/s. AVR microcontrollers are capable of meeting the stringent speed requirements for LowSpeed USB, although this solution is not recommended for higher USB speeds. Comprehensive details about physical USB communication can be found in various resources, but the documentation can be complex for beginners. A simpler explanation for novices can be found in "USB in a Nutshell" by Craig Peacock. This application note focuses on understanding the device firmware. The USB physical interface consists of four wires: two for powering the external device (VCC and GND) and two signal wires (DATA and DATA-). The power wires provide approximately 5 volts and a maximum of 500 mA. The AVR microcontroller can be powered from these VCC and GND lines. The signal wires, DATA and DATA-, facilitate communication between the host (computer) and the device, with bi-directional signal capabilities. The voltage levels are differential; when DATA is at a high level, DATA- is at a low level, with instances where both are at the same level, such as at the end of a packet (EOP). Therefore, the firmware-driven USB implementation must be able to sense or control both signals. According to USB standards, the signal wires must be driven high between 3.0V and 3.6V, while the VCC supplied by the USB host ranges from 4.4V to 5.25V. If the microcontroller is powered directly from the USB lines, a level converter is necessary to accommodate the different voltage levels. Alternatively, the VCC from the host can be regulated down to 3.3V, allowing the microcontroller to operate at that voltage. A schematic diagram illustrating the microcontroller's connection to the USB bus is provided in Figure 8, designed specifically for a USB to RS232 converter. This design incorporates direct pin control and EEPROM read/write functions. The USB data lines, DATA- and DATA, are connected to pins PB0 and PB1 on the AVR microcontroller. This connection is fixed, as the firmware utilizes an AVR-specific technique for rapid signal reception: the bit signal captured from the data lines is right-shifted from LSB (PB0) to carry and subsequently to the reception register, which collects the bits from the data lines. PB1 serves as the input signal on the 8-pin ATtiny2313, which can also function as an external interrupt (INT0) without requiring additional connections on the 8-pin version, the smallest pin count available for the AVR. For other AVR models, an external connection from DATA to the INT0 pin is necessary to maintain firmware compatibility across different microcontrollers. For proper USB device connection and signaling, the AVR functioning as a low-speed USB device must have a 1.5k pull-up resistor on DATA-. The VCC supplied by the USB host can vary from 4.4V to 5.25V and must be regulated to 3.0V to 3.6V before connecting the 1.5k pull-up resistor and powering the AVR. The voltage regulator should be dimensioned according to the power requirements of the target system and must be a low-dropout regulator. The schematic in Figure 8 utilizes an LE35 regulator with a nominal output voltage of 3.5V, although any similar solution that meets the necessary specifications can be employed. A simple regulator based on a Zener diode may also be suitable in certain cases. Additional components are required for the proper operation of the microcontroller, including a crystal as a clock source and capacitors for power supply filtering. This minimal component count is sufficient to create a functional USB device capable of communicating with a computer through the USB interface, representing a straightforward and cost-effective solution. Additional components may be incorporated to enhance device functionality, such as a TSOP1738 infrared sensor for IR signal reception or a MAX232 TTL to RS232 level converter for creating a USB to RS232 converter. LED diodes or displays can be controlled by connecting them directly to I/O pins or through resistors.The Universal Serial Bus (USB) interface has become extremely popular, due to its simplicity for end user applications (Plug and Play without restart). For developers, however, USB implementation into end systems has been more complicated compared to e.
g. RS232. In addition there is a need for device drivers as software support on the PC side. Bec ause of this, RS232 based communication is still very popular among end systems manufacturers. This interface is well established and has good operating system support, but recently the physical RS232 port has been removed from the standard PC interface, giving ground to USB ports. Implementation of USB into external devices can be done in two ways: 1. By using a microcontroller with hardware implemented USB interface. It is necessary to know how USB works and write firmware into the microcontroller accordingly. Additionally, it is necessary to create a driver on the computer side, unless if the operating system includes standard USB classes.
The main disadvantage is the lack of availability of this kind of microcontrollers and their high price compared to simple RS232 microcontrollers. 2. The second option is to use some universal converter between USB and another interface. This other interface will usually be RS232, 8-bit data bus, or TWI bus. In this case there is no need for special firmware, it isn`t even necessary to know how USB works, and no driver writing is required, as the converter vendor will offer one driver for the whole solution.
The disadvantage is the higher price of the complete system, and the greater dimensions of the complete product. The solution presented in this document is a USB implementation into a low-cost microcontroller through emulation of the USB protocol in the microcontroller firmware.
The main challenge for this design was obtaining sufficient speed. The USB bus is quite fast: LowSpeed 1. 5Mbit/s, FullSpeed 12Mbit/s, HighSpeed 480Mbit/s. The AVR microcontrollers are fully capable of meeting the hard speed requirements of LowSpeed USB. The solution is however not recommended for higher USB speeds. Extensive details regarding physical USB communication can be found at the website This documentation is very complex and difficult for beginners. A very good and simple explanation for beginners can be found in the document USB in a Nutshell. Making Sense of the USB Standard written by Craig Peacock [2]. In this application note the explanation is limited in scope to understanding the device firmware. The USB physical interface consists of 4 wires: 2 for powering the external device (VCC and GND), and 2 signal wires (DATA and DATA-).
The power wires give approximately 5 volts and max. 500mA. The AVR can be supplied from the Vcc and GND. The signal wires named DATA and DATA- handle the communication between host (computer) and device. Signals on these wires are bi-directional. Voltage levels are differential: when DATA is at high level, DATA- is at low level, but there are some cases in which DATA and DATA- are at the same level, like EOP (end of packet). Therefore, in the firmware driven USB implementation it is necessary to be able to sense or drive both these signals.
According to the USB standard the signal wires must be driven high between 3. 0-3. 6V, while the Vcc supported by the USB host is 4. 4 5. 25V. So if the microcontroller is powered directly from the USB lines, then the data lines must pass through a level converter to compensate for the different voltage levels. Another solution is to regulate the Vcc supported by the host down to 3. 3V, and run the microcontroller at that voltage level. A schematic diagram of the microcontroller connection to the USB bus is shown in Figure 8. This schematic was made for the specific purpose of a USB to RS232 converter. There were also implemented specific functions as direct pin control and EEPROM read/write. The USB data lines, DATA- and DATA, are connected to pins PB0 and PB1 on the AVR. This connection cannot be changed because the firmware makes use of an AVR finesse for fast signal reception: The bit signal captured from the data lines is right shifted from LSB (PB0) to carry and then to the reception register, which collects the bits from the data lines.
PB1 is used as input signal because on 8-pin ATtiny2313. This pin can be used as external interrupt INT0. No additional connection to INT0 is necessary the 8-pin version of the AVR is the smallest pin count available. On other AVRs, an external connection from DATA to the INT0 pin is necessary to ensure no firmware changes between different AVR microcontrollers.
For proper USB device connection and signaling, the AVR running as low speed USB device must have a 1. 5k pull-up resistor on DATA-. The Vcc supplied by the USB host may vary from 4. 4V to 5. 25V. This supply has to be regulated to 3. 0 3. 6V before connecting the 1. 5k pull-up resistor and sourcing the AVR. Dimension a voltage regulator depending on the power load of the target system. The voltage regulator must be a low drop-out regulator. The schematic in Figure 8 use a LE35 regulator with a nominal output voltage of 3. 5V. But one can use any similar solution as long as the required properties are held. Even a very simple regulator based on a Zener diode could in some cases be used. The other components provide functions for proper operation of the microcontroller only: Crystal as clock source, and capacitors for power supply filtering.
This small component count is sufficient to obtain a functional USB device, which can communicate with a computer through the USB interface. This is a very simple and inexpensive solution. Some additional components can be added to extend the device functions. A TSOP1738 infrared sensor can be used to receive an IR signal. A MAX232 TTL to RS232 level converter should be added to make a USB to RS232 converter. To control LED diodes or display, they can be connect to I/O pins directly or through resistors. 🔗 External reference
This circuit is designed to record telephone conversations on a landline telephone. It requires a small circuit and a computer subscription. Recording conversations is useful for recalling important discussions. Previously, this was accomplished using a small tape recorder, where...
The project explains how to create a simple AVR High Voltage Programmer using Arduino. It can be utilized to fix or recover incorrectly fused AVR chips.
The AVR High Voltage Programmer is designed to reprogram AVR microcontrollers that have been...
This circuit is designed for children's entertainment and can be installed on bicycles, battery-powered cars, motorcycles, as well as models and various games and toys. When switch SW1 is positioned as indicated in the circuit diagram, it generates the...
This circuit is designed to generate a loud ringing tone for an electricity bell in older telephone systems. It serves as a replacement for the original ringer that may be lost, eliminating the need for a new phone. The...
This device enables two computers to share a single USB printer or other USB devices such as an external flash drive, memory card reader, or scanner. A rotary switch is used to select the PC that will connect to...
A simple USB LED lamp circuit utilizing a 5-volt power supply sourced from a USB port, designed to illuminate a desktop or laptop computer during power outages.
The USB LED lamp circuit operates by converting the 5-volt DC power provided...
We use cookies to enhance your experience, analyze traffic, and serve personalized ads.
By clicking "Accept", you agree to our use of cookies.
Learn more