THE USB Mini V2.0 USING MAX3421 IC

 

    I had a couple USB Mini boards I got for cheap from Banggood a couple of years ago and every now and then I pull them out and spend a couple of hours banging my head to make them work. This time I persevered and Finally got this working with the DuinoFun USB Mini 2.0 boards that I have. They actually say: USB mimi v2.0. They are dated Aug. 16, 2014. Here’s how I did it.

 

HARDWARE

    I counted pins on the DuinoFun board CCW from the USB connector around the board like an IC. I skipped the pads across the other end. So, 12 pins on each long side, 1-12, 13-24. See the schematic. There is one caveat. The 5 pins 20 thru 24 are towards the inside of the board. I did not use the outer pins for P23 and P24.

Diagram, schematic

Description automatically generated

 

My Wiring Diagram

 

 

 

Used ESP32 DevKit module for ESP32. See picture here:

   https://www.arduino.cn/thread-81435-1-1.html

Credits to philipn7 for pointing out kn1cht here:

   https://github.com/espressif/arduino-esp32/issues/1271

   His insights were invaluable in getting this working because the board was mis-labeled on the bottom side. Very confusing.

 

Use ESP32 Pins     to      DuinoFun Pins      Signal and notes

    D15                        P1        SS    R2 holds D15 low at power up

    D13                        P2        MOSI

    D12                        P3        MISO

    D14                        P4        SCLK

    D17                        P23       INT

    3V3                        P9        3.3V

    VIN (almost 5V)            P24       VBUS

    D4                         P15       RST   R1 3.3K pullup on Reset

    GND                        P11       GND

 

    In order for this to work, the patch was made that removes the trace between VBUS and the 3V3 power near the 2.2K resistor on the DuinoFun board. Anyway, if wired this way, make sure P24 does not have continuity to P9. You can see an example of this patch here:

    https://www.hackster.io/139994/plug-any-usb-device-on-an-esp8266-e0ca8a

    This references an ESP8266 but is done the same way. Some USB Mini boards have a solder gap here which is much more convenient to change.

 

SOFTWARE

    Some changes to the library were necessary before I could get it to work. Per blog entry by hyshiah on this page:

    https://github.com/espressif/arduino-esp32/issues/1271

Made changes to usbhost.cpp and avrpins.h. I'm not sure if this is necessary but the whole thing is really complex, how it tries to incorporate all kinds of possible boards and initialize the SPI with the right pins. This patch adds a macro in avrpins.h to return the pin number associated with a pin name like SPI_CLK (you see them all over the place along with some function like SPI_CLK::clear(). This patch adds SPI_XXX::pinNum()) Then, another "if" is added to usbhost.h to use the new macros to call SPI.begin() with the pins as parameters. Guess it works because it now communicates with the ESP32.

    I originally had this working on the primary SPI pins on the ESP32. To use the USB Mini on the HSPI channel on the ESP32 all you need to do is change the pin assignments in the avrpins.h file. I assigned 12 to P19, 13 to P23, 14 to P18 and 15 to P5. That corresponds to MISO, MOSI, SCLK and SS. Changed the wiring to these pins and it worked so I left them that way. To use the primary SPI pins just leave these assignments as they were but make the appropriate changes to the wiring and program.

 

EXAMPLE SKETCH

    I was interested in using these chips for USB to serial converters like the CP210x chips. They weren’t supported by the official library. I wanted to change between these devices easily, be able to recover if one was pulled out, etc. But it seems that most examples just restart the sketch to reset the USB bus. So I set about to make the changes to make my way possible. I have CP210x and FTDI drivers that switch back and forth. The prolific example uses a different approach and so has not been done yet. But I don’t need it so I have left it go for further development.

    There didn’t seem to be any way to re-initialize the Usb variable, FTDI variable or the CP210x variable, to re-use them and I didn’t see any way to return them to memory. So I created initializers for all the classes that need them. They work just like the one that creates the variable except they just restart it. I also added the Reset signal so that the MAX3421 can be reset. By resetting then re-initializing, the Usb communications is reset to a new device or at a different baud rate then previously established.

    Find ESP32_USB_CP210x.ino here.

    Part of this example sends a command to change baud rate. An ordinary USB to Serial converter won’t do that. So I re-wrote my blinky program to do that too. Nothing fancy.

    Find ESP32_BLINKY_S.ino here.

    The patched up library is also here for download. I changed the folder name again but the headers for all the files are as they were in the original GitHub folders. I hope I attributed to everyone correctly. Especially Henrik Larsen who forked the original library to communicate with the CP210x. The final library may be an amalgamation of all those sited here.

You can find Henrik’s fork on GitHub at: https://github.com/henla464/USB_Host_Shield_Library_2.0

    Find the USBmini_Library.zip I made here.

 

I hope this helps somebody else who has been banging their head trying to make these things work. I hope they are inspired to do even more with it.