Generate a modified firmware for a UBW that supports reading a thermistor and communicating with a motor controller over an SPI interface.


I recently purchased a UBW (premade) and a UBW PTH kit (both 18f2553) from the Sparkfun website for a project that I am doing at my work. For this project I need to be able to read a thermistor (ADC), communicate with a Pololu Qik 2s9v1 motor controller (UART), and interface with an home brewed LED controller card which is controlled through a Digital POT with an SPI interface (SPI). When looking at the description from the sparkfun website for the UBW I believed it to be exactly what I was looking for:

  • 12 bit A/D
  • 14 General I/O
  • TX/RX (can be used as a USB to UART converter board)** **Particularly note the USB to UART converter board!

While the board from Sparkfun did include the 12bit A/D conversion, it lacked in both UART and SPI communication which I thought it included when I purchased the device. I later found out that while the PIC18f2553 had the hardware to perform hardware USART (UART… essentially the same thing… since I wanted asynchronous and didn’t care about synchronous) and SPI none of this functionality was realized in the stock 1.4.5 firmware on the UBW project site, much less the 1.4.3 firmware that came on the Sparkfun device. Since the creator of the UBW project hasn’t released the 1.5 firmware, which will supposedly include these capabilities, I decided to learn the ropes on pic programming and add it myself.

About 48 hours later I’ve finally got the hardware USART functionality working exactly as I wanted it.

Brian Schmalz the creator of the UBW project (bless his heart this piece of hardware was exactly what I needed for work!) outlined the specs for the CX, TX, and RX commands. I’ve essentially filled them out with minor changes for my application (bytes are typed in and displayed in decimal form).

In my firmware you can issue:

“CX,,” where is 0 or 1 based on if you want to do low speed (0) baud rates or high speed (1) baud rates. Then the value is set according to what baud rate I want (I used the calculator). The default configuration is a baud rate of 9600 for the 48 MHz system I have (brgh = 0, spbrg = 77).

“TX,,” where is how many bytes I intend to send and is comma separated decimal values (between 0-255) for the bytes to be sent. For example to send three bytes with values 1,2, and 3, I would issue: “TX,3,1,2,3”. If you issue a TX command with a length of 0 it will tell you how much room is available in the TX buffer.

“RX,” where specifies the number of bytes it will display from the RX buffer. If you give it a length of 0 it will tell you how many bytes of free space you have left in the RX buffer.

Additionally I added Software SPI (not hardware because the pins conflicted with the USART and SPI is easier to time in software because you have a dedicated clock line). I didn’t add the configure command for SPI as I just run Mode 0,0.

Just issue “SS,,” where is the number of bytes you want sent between the CS pin going low and high and is comma separated bytes of data in decimal form (0-255). It will return: “SS, “ where are the bytes of data in decimal form that were received when each byte of data was transmitted.

So if someone is interested in utilizing the functionality that I spent a couple days figuring out and programing and wants to just be able to install a firmware that has this functionality please feel free to download my source / firmware files.

Let me know if you need help or have questions about the functionality.

UBW FW D 1.4.5 Modified HEX (hex file)

UBW FW D 1.4.5 Modified (source files)

p.s. For the USART the TX/RX pins are the ones labeled as such on the Sparkfun boards. For the Software SPI, CS pin = RB2, Data In pin = RB3, Data Out pin = RB7, and SCK pin = RB6. *NOTE: I haven’t extensively tested the SPI at this time but I will over the next week as I use it for work. I have tested the USART and have been able to communicate with the Pololu motor controller as well as with myself (loop back line connecting tx <-> rx).