A Mutable Log

A blog by Devendra Tewari


Project maintained by tewarid Hosted on GitHub Pages — Theme by mattgraham

USB Serial firmware for ATmega32U4

This post describes how to create USB Serial firmware for the ATmega32U4 found on Adrafruit’s excellent breakout board, using Atmel Studio 7. The design of the breakout board is available from GitHub, so is the Fritzing part used in the figure below. The source code of the firmware can be forked at GitHub.

Adafruit's ATmega32U4 breakout

Source code

Creation of source code using Atmel Studio 7 is described in post Arduino USB Serial firmware from scratch. Choose adafruit_u4 as the board for LUFA Board Support (driver).

The breakout board has just one programmable LED hence the code has been adapted to blink the same LED when receiving and transmitting data.

See the wiring diagram above to see how JTAGICE3 can be wired to the ICSP header on the breakout board. The Device Programming dialog can then be used to program flash memory on the MCU, as shown below.

Device Programming

Testing and troubleshooting

The converter can be tested using another USB Serial converter connected to RX and TX wires shown in the wiring diagram. Note that the wire ending with TX should be connected to RX on the other converter, and the wire ending with RX should be connected to TX.

The firmware requires that the host send SetLineCoding request to set the baud rate, as described in Universal Serial Bus Communications Class Subclass Specification for PSTN Devices. If the host fails to do that, the serial port will not get initialized, and data cannot be sent to - or received from - the host.

The breakout board ships from Adafruit in USB powered mode. That makes it ideal as a USB Serial adapter because it can be powered from the PC it is plugged into. If your USB host device does not provide enough current on VBUS, you can cut the VCC solder jumper on the bottom side, and provide 3.3V at the VCC header pin.

VCC solder jumper

Atmel has a detailed application note on USB that has recommendations you should take into consideration in your designs.