Mespelare VSCP firmware

Main code In previous articles we’ve set up our tool chain and developed a new VSCP interface board. Before we start writing firmware for the Mespelare board, we’ll try to compile Kurtsidekick’s code for the Hasselt module. We’ll later base our own code on this foundation.

As the hardware for the Mespelare VSCP module is largely based on kurtsidekick’s Hasselt module, I will be adapting his firmware to suit my board.

Download source code

First download the source code from kurtsidekick’s Sourceforge repository. Click ‘Browse Code’ and download a snapshot of the code.

Mespelare VSCP firmware

Extract the archive in your favourite VSCP project folder, and make a copy of the Hasselt code folder.

Mespelare VSCP firmware

Configuration

We’ll need to change some configuration settings. Find the file “configurations.xml” in the “nbproject”-folder and edit it.

Mespelare VSCP firmware

There’s a key “extra-include-directories” which value needs to be set to the path we’re using for our project.

Mespelare VSCP firmware

Mespelare VSCP firmware

Start up MPLAB X IDE and open the Hasselt project

If you start up MPLAB now it will complain about two “*_reloc” files which it can’t find. Download these files first and put them in the root of the Hasselt code folder.

Now open the MPLAB X IDE. If you get the following pop-up, make sure to uncheck “Protect my computer and data”.

Mespelare VSCP firmware

Once MPLAB is running, select “File” - “Open project”.

Mespelare VSCP firmware

Now select the Hasselt code folder you just copied from the downloaded archive.

Mespelare VSCP firmware

MPLAB should now be open with the following screen. There should be no load errors.

Mespelare VSCP firmware

Setting the correct target micro-controller

Before we can compile the code, we need to let MPLAB know what the target micro-controller is that we want to compile code for. This is a three-step operation:

  • Go to “Run” - “Set project Configuration” - “Customize”, and select 18F45K80 from the “Device” menu.

Mespelare VSCP firmware

Mespelare VSCP firmware

  • Create a file in the project root called “p18cxxx.h”, with the following line:

    #include <p18f25k80.h>

Or download it here

  • The can18F66K80 file checks if a compatible PIC model was defined, and fails with an error if there isn’t.

    C:\vscp\Hasselt_v2.X\can18F66K80.c:447:Error [1099] “PIC 18Fxxx(x) not supported.”

The 18K25K80 is supported, the 18K45K80 isn’t. There should not be any reason the 45K80 isn’t supported since it is essentially a 25K80 with more pins, so we’ll trick the can18F66K80-file just a little bit.

Change the lines that read

#elif defined(__18F25K80) 

into

#elif defined(__18F25K80) || defined(__18F45K80) 

(You can double-click the error line and MPLAB will take you to the offending line of code.)

Mespelare VSCP firmware

There’s another line that needs the same change:

Mespelare VSCP firmware

Preserving the EEPROM memory

By default MPLAB will overwrite the program memory and the EEPROM memory when programming. The latter isn’t desirable since our source code saves the VSCP registers in EEPROM. If they are erased every time the PIC is reprogrammed, we’ll need to re-load the registers through the Device Configuration window over and over again. We’ll therefore configure MPLAB to preserve the EEPROM data that is already present in the microcontroller.

In MPLAB, open the File - Project Properties menu item, and click the Conf: [default] - PICkit 3 item from the Categories tree. Mespelare VSCP firmware

From the Option Categories drop down on top, select Memories to Program and check the box next to the Preserve EEPROM Memory item. Done. Mespelare VSCP firmware

Compiling the code

Now we should be ready to attempt a compile. I suggest you do a “clean and compile” first to remove any garbage that was left in the downloaded snapshot of the code.

Mespelare VSCP firmware

The build should result in a message saying

BUILD SUCCESSFUL 

Mespelare VSCP firmware

If so, congratulations! If not, check the error messages that MPLAB throws for any clues about what might go wrong.

The compile left a .HEX file in the \dist\default\production folder.

Mespelare VSCP firmware

Let’s see if we can program it onto our test board.

Programming the test board

As mentioned, I am using the PICkit 3 Programmer stand-alone application. Let’s fire it up.

  • Start the programming application
  • Click the “Auto Import Hex + Write Device” button. This will monitor the hex file for any changes, and automagically program the PIC for us as we change and re-build the code in MPLAB.

Mespelare VSCP firmware

Possibly the PICkit3 will need to load new firmware to be able to program the 18F45K80. If it asks, first check if you’ve selected the correct device to program. If that’s correct, it’s OK to let it download new firmware.

Mespelare VSCP firmware

Voila, now we’ve compiled and programmed custom firmware on the Mespelare board for the first time. Obviously it won’t work correctly since it was intended for use on the Hasselt firmware.

In the next article we’ll customize the code for our Mespelare module.

Resources

Comments