VSCP over CANbus with Atmel devices - PART 1 - Blink a led

The purpose of this document is to show how to implement some of the most important VSCP features on a CAN bus using Atmel devices (AT90CAN32).

As I write those lines, I have never used VSCP before, therefore I will describe the process step by step as I learn how to use VSCP.


As the name of this page says, this page is intended for begginers, however you need to have some knowledge to be able to start. What you need is:

  • know how to connect electronic components on a test board
  • know how to write a program on a micro-controller device
  • Ideally have some knowledge on C programming
  • some knowledge on Atmel devices since this example is done using Atmel micro-controller

I use a Linux computer to create the code and program the devices:

  • Sublime Text for file editing
  • avr-gcc for compiling
  • avrdude to write the program on the devices

You might also need those tools or the equivalents for your computer's operating system.

As an example, with the knowledge I have, I have been able to send a message on the CAN bus from one chip, receive it with another chip on the bus and print this message on a computer's screen via UART interface (all this without using VSCP yet). This is the basic skills I have at the moment.

In fact I'd like to make this documentation easy enough to follow that you only need to know how to make a LED blinking with a AT90CANXXX.

Project specification

Below is what we expect from the outcome of this test.

First, according to VSCP specification, both chip A and B will start, the status LED should blink until the start-up process is completed. When start-up is completed, both status LEDs should be steady, both devices will get their nicknames and be ready to operate.

The operational functionality should be as per below:

  • when a button connected to chip A is pressed, chip A should send an event on the bus (class 0x14 - information, type 0x03 - on)
  • chip B will receive the message and should be able to know which button has been pressed
  • using Decision Matrix, chip B will toggle either LED 1 if button 1 has been pressed, or LED 2 if button 2 has been pressed

It seems fairly simple, let's see if we'll be able to make it work ;-)


There is the hardware used for this project:

Yes, you've never seen such an ugly test board, however, it works and might be good enough to start with. We'll see later if I can make a nice SMD PCB :-).

VSCP specification says you need a switch on each node to start the init process for nickname discovery. Because only one node per time can perform the nickname discovery. If a nickname is already assigned, the node go direct to active state without any user interaction. Also a status led needs to be added to get visual information about the init status.

The chips are AT90CAN32, they only come in SMD packages that's why you need to have them on break-out PCBs to be able to use them on a breadboard. That's the alternative I have found, I'm sure you can find a much better solution.


  • Init switches connecting PA0 to 0V
  • Button 1 connecting PA1 with pull-up resistor
  • Button 2 connecting PA2 with pull-up resistor
  • Init switches connecting PA0 to 0V
  • Status LEDs connecting PB0 to +5V
  • LED1 connecting PC0 to 0V
  • LED2 connecting PC1 to 0V
  • both chips have 16Mhz crystals
  • using one MAX232 for UART connection to computer for debug (or USB virtual com port using FT232 or PL2303HX converter)
  • the rest of the connection is standard, power, CAN drivers, etc… are connected to usual ports

You need to set the AT90CAN32 with 16MHz external crystal, in order to do so issue the following command:

avrdude -p c32 -P usb -c avrispmkII -U lfuse:w:0xEE:m

That's all we need for the hardware, let's start the fun stuff!


Get firmware source from GIT repository

You need to install a git client, on the Linux distribution used in this example (Gentoo), the package is simply called 'git'.

Create a vscp directory to store a local copy of the repository (my username is 'mamac')
cd /home/mamac/Electronic/
mkdir vscp
Change to the folder where you want to download the sources
cd ~/Electronic/vscp
Download VSCP source files
git clone https://github.com/grodansparadis/vscp_firmware
git clone https://github.com/grodansparadis/vscp_software

You can go and get a cup of coffee, this takes a while.

To update your local repository to the newest commit, execute
git pull

Preparing the working directory

I created a new directory ~/Electronic/vscp/vscp_firmware/avr/demo_AT90CAN32/ where I placed all necessary code for a demo program. This directory has been created based on demo_vscp_node_can128. You can find this directory in the git repository.

The VSCP project team has kindly created a bunch of headers and .c files that you should include into your project folder.

You need to create some project specific files and make a reference to common VSCP files:

  • create vscp_compiler.h for that specific project (you can find examples from the source repository)
  • create vscp_projdefs.h for that specific project (you can find examples from the source repository)

In order to get the Makefile to work, you need to set global variables called VSCP_HOME, VSCP_FIRMWARE and VSCP_SOFTWARE, with Linux you can add lines in your .bash_profile:

export VSCP_HOME=~/Electronic/vscp/vscp_software
export VSCP_SOFTWARE=~/Electronic/vscp/vscp_software
export VSCP_FIRMWARE=~/Electronic/vscp/vscp_firmware

Programming the nodes

At this stage of the preparation you should be able to build the demo code and program the device.

Below is a command that can be used to build the code and write it onto the devices (both TX and RX devices) Using Linux with avr-gcc and avrdude:

make clean && make && /usr/bin/avrdude  -p c32 -P usb -c avrispmkII -U flash:w:demo_vscp_node_can32.hex -U eeprom:w:demo_vscp_node_can32_eeprom.hex

Once programmed, the device should execute the init process, the video below show the init process of one node:

A second video shows the init process on both nodes and control of LEDs using switches:

Where to go from here

You can move on to the PART 2 to see how to read CANbus messages on your computer using VSCP Works.

howto/vscp_can_atmel_part1.txt · Last modified: 2014/11/11 22:48 by jmbeaune
[unknown button type]
Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki