Posts

Arduino USB host – Pre-prototyping.

Arduino USB Host Shield prototype

Arduino USB Host Shield prototype


I have been thinking about expanding ways to use my recently conceived USB Host controller based on MAX3421E. Nice and very popular AVR development platform called Arduino looked like logical target. After quick Internet search, I went to SparkFun to pick up an 3.3V 8 MHz Atmega168 Arduino Pro, a protoshield, and USB to serial cable. After checking that everything works fine together, I populated a MAX3421E breakout and soldered it on the top of protoshield ( see schematic ).

I wanted to make a quick prototype and not worry about level translation for now. Arduino Pro is 3.3V and is able to talk to MAX3421E directly. The circuitry to adapt this shield for 5V Arduinos will be added later. This is going to be interesting since MAX3421E is not only a USB controller but also a port expander. It provides 8 general purpose outputs and 8 inputs, which can be configured as interrupt sources, all accessible via SPI. I’m using 1 input and 1 output for Vbus tracking, the rest is available for general use.

In order to use Atmega’s SPI peripheral I imported SPI library from Arduino playground. The default initialization will work. Below is the quick sketch that I wrote to make sure that MAX3421E is talking. Here I’m defining pins, setting initial state, and configuring MAX3421E SPI to full-duplex mode. This is not the right way to initialize MAX3421E, however, the beauty of this controller is that its SPI subsystem is separate from the rest of the chip and will work in any state as long as power is applied. No fancy resets are necessary.


Continue reading Arduino USB host – Pre-prototyping.

Lightweight USB Host. Part 4 – The code.

MAX3421E breakout

MAX3421E breakout


A couple of updates. First, second prototype for the breakout board arrived from BatchPCB (pictured on the right ). I placed an order for the first batch with PCBcart, it is supposed to be here in 2 weeks. Also, I made this prototype public at BatchPCB, this is the product link. The prototype has a little defect – the USB connector is placed a little bit too close to resistors; however, it’s totally buildable, just make sure you insert USB connector last, when the rest is soldered and checked.

Second, I created a code repository for the project. From now on, all firmware development will be posted there. The hardware files don’t change that often; they will still be hosted here in downloads section.

At present, the code doesn’t do much past enumeration. From USB point of view, it knows how to generate control and bulk-IN transfers; bulk-OUT is going to be written together with mass storage client driver code, which is going to be next big step. Also, it is probably buggy and this is my reason for publishing it – “given enough eyeballs, all bugs are shallow”. If you try the code and it doesn’t work, let me know. Or better yet, fork a code, fix it and let me know what you fixed and why.


Continue reading Lightweight USB Host. Part 4 – The code.

Lightweight USB Host. Part 3 – accessing MAX3421E.

MAX3421E protoboard setup

MAX3421E protoboard setup


In previous article I wrote about ways to build the project. Picture on the right shows one built on a piece of protoboard. The PIC is clocked at 64MHz using internal oscillator and SPI clock is 16MHz. It works well.
I’d like to start describing the code with an overview of a project layout. All project-related definitions are contained in project_config.h file. Types like BYTE, WORD, BOOL are defined in Generic_Types.h, the rest goes to a header file with the same name as .c module.

At present, the code consists of SPI functions, MAX3421E register read/write functions, MAX3421E event handler, and a small CLI used primarily to aid in debugging. SPI functions are explained in Interfacing LCD via SPI article, take a look if you haven’t already. In this article I will be talking about MAX3421E low-level routines.


Continue reading Lightweight USB Host. Part 3 – accessing MAX3421E.

Lightweight USB Host. Part 2 – Hardware.

MAX3421E breakout board schematic

MAX3421E breakout board schematic

As I mentioned in the previous article of this series, the schematic of MAX3421E board differs very little from datasheet reference design. It consists of MAX3421E itself, MAX4793 USB current-limiting switch, MAX6349 3.3V regulator, plus a dash of resistors, capacitors and connectors. Some parts are optional; for example, if you prefer leaving USB power line (called Vbus) unrestricted, don’t solder MAX4793. Also, if you don’t mind using 2 power supplies – 5V to supply Vbus, and 3.3V for MAX3421E, then leave MAX6349 unpopulated as well. Alternative power pins are provided on the board.

The 3.3V regulator can also be substituted with LDOs from other manufacturers either “drop-in”, like ones from National Semiconductor (example: LP3990) or with minor modification – cutting a trace or two (example: TC1040 from Microchip). Look for LDO in SOT-223 package and check pin assignment against MAX6349 datasheet.


Continue reading Lightweight USB Host. Part 2 – Hardware.

Lightweight USB Host. Part 1 – Motivation.

Lightweight USB Host

Lightweight USB Host


Universal serial bus is quite popular. USB peripherals are aplenty, and they are cheap; therefore,it is tempting to use them in microcontroller projects.

There are two distinctive roles for devices on USB bus. USB host controls the bus and initiates data exchanges. Peripheral device won’t do anything until instructed by host. In other words, to make use of USB peripheral, our little microcontroller has to become a USB host.

Making a USB host is not as difficult and scary as it sounds. We don’t need a functionality of a PC USB host controller. USB specification for embedded host says that such host need only support a certain set of devices or device classes and nothing else. What is in this set (called Target peripheral List, or TPL ) is up to you. You may want your micro to work with a certain web camera or printer, or use memory sticks, which are all “Mass Storage Class Bulk Only Transfer” devices, or Bluetooth radios, or whatever else you may need in your design.


Continue reading Lightweight USB Host. Part 1 – Motivation.