PIC 16F1455 USB Dev board

Recently, as I have blogged, I bought a number of PIC 16F1455's from Microchip as pre-full-production samples, as I was intrigued by the idea of a PIC 16 with a hardware USB port on it (all other USB pics are in the bigger, meaner PIC 18 and higher ranges). It also has a few other nice features:

All in a 14 pin package! Theres also a "bigger brother" version with 28 pins that has more I/O principally.

This meant having to set up my dev environment for C programming, as usually I write assembler (I'm a masochist, OK?). However I wastn't going to muck about with a USB stack in assembler...

After my last blog post I got a nice tweet from Tim H at microchip telling me that the USB stack for the 16F was in the latest Microchip Library and all I needed was a recent version of MPLAB-X and XC8. I've still been using the older MPLAB 8 because I found the simulator more reliable, but I decided to bite the bullet and set up MPLAB-X and start learning to use that instead.

I also only had a PICkit2 programmer, and although its not supported for the enhanced mid-range devices through the IDE, the command line utility programs them, so intended to carry on with that. Alas, I discovered that the PIC 16F1455 was not supported by the latest version of the command line utility which is a shame, but not entirely suprising. I had to order a PICkit3 and send my PICkit2 to the dusty storage bins :)

DEV Board

There is, of course, no official dev board, but for low pin count devices its simple enough to roll your own. I sketched out a schematic (literally!) on the back of an envelope:


and after a while (which took me a while because of other commitments) I ended up with this (I added an LED and resistor that connects to RA5 via the jumper you can see next to the connector):

usbpic/devboard1.png usbpic/devboard2.png

Now to C! Well, I've programmed in C for years on mainframes and PCs but never in an embedded setting, so this was a step into the unknown.

However, as these things usually are, it turned out easier than I anticipated and I ended up with the code as follows:

// USBtest
// This is a program used to test the pic 16F1455 8 bit microcontroller
// with hardware USB!!
// Its also my first attempt at PIC C...

#include <xc.h>
#pragma config  MCLRE=ON, CP=OFF, BOREN=OFF, WDTE=OFF, \
                STVREN=OFF, PLLMULT=3x, BORV=HI, LVP=ON

#define _XTAL_FREQ 48000000

/***** MAIN PROGRAM *****/
void main()
//*** Initialisation
    // Set up clock for 48Mhz
    OSCCONbits.SPLLMULT = 1;
    //OSCCONbits.SPLLEN = 1; // Not reqd since config PLLEN=ENABLED

    // configure port
    ANSELA = 0b00000000; // Disable analogue inputs on port A
    TRISA = ~(1<<_LATA_LATA5_POSN); // configure RA5 (only) as an output
    LATAbits.LATA5 = 1; // Switch on
    //*** Main loop
        LATAbits.LATA5 = 0;
        LATAbits.LATA5 = 1;

// loop forever

Well (as you can see from the photo's) I got that all to work recently and now have to work on the USB stack...! It did take 5 attempts to get the clock speed settings right, as the data sheet is a tad vague in places, and appears to be contradictory in places (although once you've worked it out you can see that its not, its just what it DOESNT say is misleading!).

I'm not sure I'm going to use Microchip's USB stack (Hey, why do things the easy way!) as its not open source and that will make publishing code, projects etc a pain, as people would have to go get the huge 150Mb download of all of Microchips libraries for the few thousand bytes they actually need. There are a couple of open source libraries I've seen, and it will be interesting and educational for me to see if I can adapt them to work on the 16F1455.

Watch this space!!

Version 2 updated Oct. 12, 2012, 5:50 p.m.