Documentation for Firmware D, version 1.1 for UBW Boards
SparkFun ships this fimware version on their UBW boards
Back to main UBW page

Description:
Firmware version D is a more advanced (and more complicated) firmware version than Firmware C. Wheras C just allows you to write out 8 bits at a time to Port B, Firmware D allows you to use every one of the 19 I/O pins on the UBW Board as an input or an output, and to read the state of every one of those pins. In order to do this, it has an actual command structure that must be followed when communicating with it.

(Note: If you want the latest version of Firmware D, check here for version 1.3)

Commands:
    The "C" Command:
    The "O" Command:
    The "I" Command
    The "V" Command (new for version 1.1)
    The "R" Command (new for version 1.1)
   The "T" Command (new for version 1.1)

Hints on using Firmware D:

Errors:
    There are some rules about sending these commands to the UBW. If any of the rules is violated, an error charater will be sent back. You can monitor the serial port for these characters to know what you are doing wrong.
    Other things to note:

Files:
    The full zip file for Firmware D v1.1, including all source and project files necessary to rebuilt it are located here.

Example Liberty Basic Application:
    This is a very, very simple app that illustrates how to talk to Firmware D.

' This is a super-simple demo of how to use Firmware D on a UBW board
' Step through this in the debugger to see everything in slow motion
' To be used with Firmware D v 1.1 or above

' First we open the COM port that we're going to use (COM15 for me)
print "Opening com port"
open "COM15:9600,8,N,1,RS,DS0,CS0" for random as #commHandle

' Then we write a C packet with the directions we want for each pin
' All of port A will be inputs and all of port B and C will be outputs.
print "Setting direction registers"
print #commHandle, "C,255,0,0,0"

' Then we're going to write out an O packet with the values for the pins that are outputs
' We'll make all of Port C high (which will turn on the yellow LED on the UBW)
print "Setting bit states"
print #commHandle, "O,0,0,255"

' Then we'll wait for one of our input pins to go High with an I command
print "Waiting for PortA bit 0 to go high"
[WaitForHigh]
    ' First send the I command
    print #commHandle, "I"

    ' Wait for something to come back
    while lof(#commHandle) < 1
        scan
    wend

    ' Read in what was sent to us
    DataIn$ = input$(#commHandle, lof(#commHandle))

    ' Check to make sure it's what we wanted
    if left$(DataIn$,2) = "I," then
        ' "I,AAA,BBB,CCC" and pull appart the packet
        StatusA = val(mid$(DataIn$, 3, 3))
        StatusB = val(mid$(DataIn$, 7, 3))
        StatusC = val(mid$(DataIn$, 11, 3))

        ' Now check to see if Port A, bit 0 is high
        if TstBit(StatusA,0) = 1 then
            goto [NextStep]
        end if

    end if
    scan
    goto [WaitForHigh]

' Then Low
[NextStep]
print "Waiting for PortA bit 0 to go low"
[WaitForLow]
    ' First send the I command
    print #commHandle, "I"

    ' Wait for something to come back
    while lof(#commHandle) < 1
        scan
    wend
    ' Read in what was sent to us
    DataIn$ = input$(#commHandle, lof(#commHandle))

    ' Check to make sure it's what we wanted
    if left$(DataIn$,2) = "I," then

        ' "I,AAA,BBB,CCC" and pull appart the packet
        StatusA = val(mid$(DataIn$, 3, 3))
        StatusB = val(mid$(DataIn$, 7, 3))
        StatusC = val(mid$(DataIn$, 11, 3))

        ' Now check to see if Port A, bit 0 is Low
        if TstBit(StatusA,0) = 0 then
            goto [Done]
        end if
    end if

    goto [WaitForLow]

' And finally we'll write out another set of values to the pins with the O command
' All output bits will be low.
[Done]
print "Writing out final bit states"
print #commHandle, "O,0,0,0"+chr$(13);

' And now we're done!
print "Closing com port"
close #commHandle
END


' Test bit "Bit" (zero based) in variable "Byte" and return it's value (1 or 0)
function TstBit(Byte, Bit)
    TestBit = 0

    if ((Byte AND (2^Bit)) > 0) then
        TstBit = 1
    end if
end function


Back to main UBW page
Questions? E-mail me at my e-mail address