Using the MCP2515 CAN bus interface with the Acme AriaG25

Posted on May 31st, 2013, 11:29 amby Geert

In this article I will explain how to get the Acme systems Terra board (or just the AriaG25 module) connected to a CAN Bus using the Microchip MCP2515 CAN controller. I assume you already know how to wire this chip to the CAN bus, you need a line driver/receiver in between the MCP2515 and the bus. For example the MCP2551. Note that most of these drivers need a 5V supply. The MCP2515 itself normally also runs on 5Volts, but I recommend supplying it the 3.3V from the Terra/Aria (still within specs), as you will run into level problems with the SPI interface otherwise. Don’t forget to tie the 5 and 3.3V grounds together when using an external 5V supply.

Connecting the MCP2515 to the Terra board.

I have wired the SPI pins on the MCP2515 to the Terra board, using the Daisy D15 connector. Signal names speak for themselves, you need MISO, MOSI, SCK (SPCK) and CS. (NPCS0). If you connect straight to the AriaG25 module, use pins S9 thru S12. Be sure to tie the /RESET pin on the MCP chip to VCC. You don’t need the ..RTS and ..BF pins. What you do need however is an interrupt line. A GPIO pin can be used on the Aria module for this purpose. However there’s no GPIO signal in the D15 connector so I used the D12 connector to get to the PC14 pin (N16 on the Aria module). You are free to choose any GPIO.

Compiling the kernel

Once all connections are made, the next step is to make sure you are able to compile a kernel. Use the article on the Acme site about kernel compiling to set things up. Once you are able to create a uImage file, you can start configuring the kernel for the CAN bus.

In the kernel configuration menu, enable the SPI driver in Device Drivers -> SPI Support. Make sure the Atmel SPI is enabled.

Ensure the board is set to SAM9e5ek, by going to System type. ARM system type should be AT91. Proceed into AT91 system on a chip. Under Board type there should be a line saying AT91SAM9X5 series evaluation kit. That should be selected.

Go to Networking Support -> CAN bus subsystem support, and enable the RAW CAN protocoll. Proceed to CAN Device drivers, and enable the Platform CAN Drivers, and then the Microchip MCP251X.board-sam9x5ek.c

In order to be able to verify the interrupt line operation, go to Kernel hacking, and enable the Debug Filesystem.

Save the configuration.

Edit the board specific configuration file. Since we selected the AT91SAM9X5 evaluation kit, the file is in arch/arm/mach-at91/board-sam9x5ek.c In the includes list, add this line:

#include <linux/can/platform/mcp251x.h>

Then locate the line: static struct spi_board_info ariag25_spi_devices[] =
Before this line, add this struct:

Check if your interrupt is registered correctly by viewing /sys/kernel/debug/at91_gpio.
Your requested interrupt should be in this list, like14: GPIO:1 GPIO:1 IRQ:edge-falling GPIO:1

You are now ready to send test messages. There is a set of tools that do this, but you have to download the sources and compile them on the AriaG25 first. You can obtain these sources from the BerliOS website.

When the utilities have compiled and you have put the in the appropriate directories, you can now send a testmessage with the command:

cansend 100#11.12.13.14

This command will send a CAN frame with identifier 100, and four databytes with values 11, 12 and 13.

You can also test recieving of frames with the candump utility:

candump can0

This is the end of the article. You can now start writing your own applications using the CAN bus. A good point to start is this Wikipedia article that contains more links at the bottom of the page. Good luck!