Andrew Kroll and I were talking a lot about running USB Host Shield at higher SPI speeds. We were discussing one peculiar case of seemingly defective SPI master module and were needed full sized shield-compatible host board with fast SPI to check our theories when I realized that I have two Digilent ChipKIT Uno32 boards sitting in my ever expanding “to-do” pile of projects. I sent one to Andrew and soon he made a port which compiles under Digilent’s IDE and runs on chipKIT boards, although we only tested on Uno32 (rev.B).
It should be noted that another good candidate for the host board capable of high-speed SPI would be Arduino DUE. It is supported by the library and presumably runs at up to 24 MHz SPI speed with full-size shield. Incidentally, none of us have a DUE so we can’t test. Donations are gladly accepted.
The chipKIT support is currently in beta. At the moment, the only code example I have verified is Board QC routine – a program I’m using to test the shields before selling them to people. The port lives in xxxajk branch. Making other examples work should be a simple matter of (quoting Andrew) “including the right SPI.h”. Indeed, nothing in the library relies on SPI speed so increasing it would simply allow data to be sent faster.
In this article I will show how I modified a standard full size USB Host shield rev.2.0 to run on chipKIT Uno32 board at high SPI speed. I was able to run up to 20 MHz; unfortunately, the next available SPI rate on Uno32 is 40 MHz which is too high for the MAX3421E chip. The modded shield can be seen on a title picture (click on it to make it larger). Uno32 is 3.3V board; even though the inputs on PIC32 on-board MCU are 5V tolerant and it is likely possible to run the shield as-is I removed the level shifting ICs, which are unnecessary when interfacing the shield with 3.3V boards and could decrease error margin. Also, the RESET line on the ICSP connector on Uno32 has been replaced with CS by Uno32 designer, perhaps to make it look more like SPI, so I also needed to disconnect and reroute it. Here is the implementation, step-by-step.
First step is to disconnect pin 5 of the ICSP connector. It is connected to the reset line of USB Host controller on the shield and CS line on Uno32 SPI module – this will never work. The easiest way to break the connection is to remove a contact from pin 5. This can be done from either side, Uno32 or the shield. On Uno32 it is quite trivial: pin 5 can be simply cut off. However, this will also remove CS signal which could be useful for other shields. Removing the contact from the shield side is just slightly harder. Since I’m starting with a shield with 2×3 connector un-soldered, I first pull the contact from pin 5 and then solder on the connector. Picture on the left shows modified connector ready to be put in place.
For those who has the ICSP connector already in place the procedure is again just slightly harder. The trick is to deal with individual contacts rather than the whole assembly. In order to achieve this you can pull the plastic cover off the contacts grabbing it with a pair of pliers or prying it off with a pair of flat screwdrivers. The contact on pin 5 can then be de-soldered without much difficulty and connector reassembled. Take a look at the picture on the right to see the connector with pin 5 removed and ready to be put back together.
After this was done I removed two level-shifting ICs using hot air and closed the 6 solder jumpers situated around the ICs. I don’t have a closeup of it, please refer to the title picture.
The next step is to provide a reset line to the MAX3421E. I ran a wire from now vacant pin 5 of the ICSP connector and reset pin on the side of Uno32 board. This gives me properly functioning reset button. The reset can also be simply pulled up to 3.3V through 10K resistor. One end of the resistor can be soldered to pin 5 and the other one to the pin 14 of now vacant footprint of AHC level shifter.
This concludes the shield modification. The Uno32 will work as-is, with the JP4 jumper set to RD4 position. Curiously, this is also a setting for CS signal – in order for the shield to function CS must be routed to pin 10. After this is done the shield can be connected to Uno32 as usual. The code is on github in ‘xxxajk’ branch and will compile in the current revision of MPIDE. One thing I’d like to point out is SPI speed setting. In order to run at speeds higher than 8 MHz a
SPI.setClockDivider(x); shall be placed after this line.
X could be ‘1’ or ‘2’. This oscilloscope screenshot shows SPI SCK signal with clock divider set to ‘1’ and it looks like 20 MHz to me.
The code and shield modification described in this article were made for the problem we were solving and I’m not even sure anyone will be interested in it – as far as I can see Digilent boards are not particularly popular. If you think further development could be useful please let us know – github issue tracker is perhaps the best place for that.
Thank you for your interest!