Learning About Arduino and AVR-USB
( Current status : Research—consider electrical details unverified)
See also: ProjectLogArduinoUSB
Potential Software Issues
- Bad interaction between interrupts, timers and/or pins used for Arduino or AVR-USB.
- The AVR-USB file usbconfig.h has the following section:
/* ----------------------- Optional MCU Description ------------------------ */ /* The following configurations have working defaults in usbdrv.h. You * usually don't need to set them explicitly. Only if you want to run * the driver on a device which is not yet supported or with a compiler * which is not fully supported (such as IAR C) or if you use a differnt * interrupt than INT0, you may have to define some of these. */ /* #define USB_INTR_CFG MCUCR */ /* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */ /* #define USB_INTR_CFG_CLR 0 */ /* #define USB_INTR_ENABLE GIMSK */ /* #define USB_INTR_ENABLE_BIT INT0 */ /* #define USB_INTR_PENDING GIFR */ /* #define USB_INTR_PENDING_BIT INTF0 */
- The AVR-USB file usbdrv.h notes:
Hardware Prerequisites: ======================= USB lines D+ and D- MUST be wired to the same I/O port. D+ must (also) be connected to INT0.
Interrupt latency: The application must ensure that the USB interrupt is not disabled for more than 20 cycles. This implies that all interrupt routines must either be declared as "INTERRUPT" instead of "SIGNAL" (see "avr/signal.h") or that they are written in assembler with "sei" as the first instruction.
Note: SIGNAL(SIG_OVERFLOW0) is used in 'wiring.c' linked above.
Maximum interrupt duration / CPU cycle consumption: The driver handles all USB communication during the interrupt service routine. The routine will not return before an entire USB message is received and the reply is sent. This may be up to ca. 1200 cycles = 100us if the host conforms to the standard. The driver will consume CPU cycles for all USB messages, even if they address another (low-speed) device on the same bus.
USB and 5V (5 volt)
According to various sources the USB specification requires D+ and D- to be 3.3V lines. If the circuit supply is 5V this will not be the case without additional components. The standard way of ensuring the correct voltage on the data lines seems to be to use ~250mW (?) 3.6V Zener diodes on the lines.
While some systems appear to cope with 5V data lines it is out of specification. The reason for using 3.6V diodes rather than 3.3V diodes is apparently to do with the current/voltage curve characteristics of the device—for the current present on the data lines 3.6V diodes deliver the 3.3V required.
@@TODO: Add links.
USB and External Power
My current supposition is that to connect an externally powered USB device to the USB connector requires leaving V+ (Vbus) unconnected while having connections to D+, D- and GND. I could be wrong about this. (Please email me if I am wrong.) (And/or you at least need a diode on Vbus for a dual-power system?)
My assumption is the Arduino is considered externally powered when it's powered by USB via the serial USB adapter and is using its digital I/O lines as data lines.
Here are some circuits or descriptions that have led me to this conclusion:
- "The ICSP don't need power from the Pic circuit, don't connect power from the GTP USB to power from the Pic circuit, only connect the ground of both circuits and Vpp, Data and Clock."
- "We have released a new version of AVR-USB today which solves at least the cyrstal frequency issue: This version can be configured to run off a 12 MHz or 16 MHz crystal clock or a 16.5 MHz RC oscillator clock."
- USB-Tiny -- Alternative USB implementation for AVR (Includes Python binding)
- Arduino#Bootloader10 -- Note about using "normal" (i.e. non-Arduino specific) Atmega/AVR code on an Arduino board.
- USB Made Simple -- "A Series of Articles on USB"
- USB Central -- "Information, tools, and links to material about the Universal Serial Bus"
- Run Arduino code on a Micropendous -- "LUFAduino combines the LUFA USB library, the Arduino library, and the preemptive FreeRTOS kernel to enable programming Micropendous boards in Arduino code"