Shopping Cart

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.

/* MAX3421E USB Host controller main routine */
#include <Spi.h>
#include "WProgram.h"
#include "MAX3421E.h"
 
/* pin definitions */
#define MAX_SS    10
#define MAX_INT   9
#define MAX_GPX   8
#define MAX_RESET 7
 
void setup();
void loop();
 
void setup()
{
  /* setup pins */
  pinMode( MAX_INT, INPUT);
  pinMode( MAX_GPX, INPUT );
  pinMode( MAX_SS, OUTPUT );
  digitalWrite( MAX_SS, HIGH );    //deselect MAX3421E
  pinMode( MAX_RESET, OUTPUT );
  digitalWrite( MAX_RESET, HIGH );  //release MAX3421E from reset 
  /* setup SPI */
  /* default is good */
  /* setting up USART */
  Serial.begin( 9600 );
  /* setup MAX3421 */
  digitalWrite( MAX_SS, LOW );                    //select MAX3421E
  Spi.transfer( rPINCTL + 2 );                    //set full-duplex
  Spi.transfer( bmFDUPSPI+bmINTLEVEL+bmGPXB );  
  digitalWrite( MAX_SS, HIGH );  
}
 
void loop()
{
 byte a;  
  delay( 100 );
  digitalWrite( MAX_SS, LOW );    //select MAX3421E
  Spi.transfer( 0x90 );      //send REVISION register address
  a = Spi.transfer( 0x00 );  //read next byte
  digitalWrite( MAX_SS, HIGH );   //deselect MAX3421E
  Serial.print( a, HEX );
}

In the main loop I query REVISION register. This is the only register which will contain meaningful information even if not reset properly. The picture below is a screen shot of my logic analyzer output showing byte 0×90 sent to MAX3421E and 0×12( which means revision 2 ) sent back in the second transmission.

MAX3421E REVISION register query

MAX3421E REVISION register query

I will be posting my progress here. The next step is going to be writing classes for MAX3421E and low-level USB functions.

Oleg.

Related posts:

  1. Arduino USB Host Mini – initial revision
  2. Digital camera control using Arduino USB Host Shield. Part 1 – basics.
  3. PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 3
  4. PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 2
  5. PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 1
  6. How to drive USB keyboard from Arduino
  7. Arduino USB Host – Peripherals.
  8. USB Host Shield for Arduino – first prototype.
  9. Arduino USB Host – USB Descriptors.
  10. Arduino USB host – First programs.

4 comments to Arduino USB host – Pre-prototyping.

  • usbspy

    Hi,

    I am trying to implement spi to usb with the max3420e. I am using a FPGA to talk to the max3420e.
    Do I need to check any USB interrupt registers or pins.
    These are the steps I am following -

    1. Make SS low and write command byte to register R17 (PINCTL) to enable Full duplex SPI
    2. Make SS low and select EP2INFIFO register and write data bytes
    3. Make SS low and select EP2INBC register and write the # of data bytes written

    This should make data appear on the PC, right?
    I had a notepad open. Nothing happened.
    But it doesn’t work. I tried writing to GP0 register and it works. So I am able to talk to the MAX3420.
    Any help would be great.

    Thanks.

    • I’m not sure what you mean by “SPI to USB”, but if you are trying to send data to the PC via USB using MAX3420, you first need to perform enumeration and start appropriate driver on a PC.

  • keips

    hi im making a project which is USB/Flash drive as a door key,, my question is can i use arduino to read the code that is installed in my usb and then execute it? and also what software did you use in programming the arduino? pls help me ,,

    • It depends on what you want to read off of Flash drive. If you can use drive’s serial number, which is unique for the drive, this can be done with the code which is already written since it’s just a string descriptor. If you need full support for flash drive, then you would need to write it – currently, flash drives are not supported.

      As far as programming, it’s standard Arduino package from arduino.cc.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">