CAN Bus via MCP2515

Hey guys,

I am currently trying to get a CAN bus interface working upon the Hikey through the use of an MCP2515, which I have connected via the SPI within the Lo-speed connector.

It is of my understanding that to enable this, some slight modifications need to be made to the device tree files. I have not, however, been able to get the MCP2515 recognised as an SPI device, or the can0 interface to appear within Linux.

I am new to anything related to device trees, and so have made attempts at altering the approaches made within these two posts:

  • http://www.96boards.org/forums/topic/get-can-bus-working-on-db410c-via-mcp2515/
  • https://github.com/raspberrypi/firmware/issues/371

Currently my device tree file looks like the following:


#include "hikey-gpio.dtsi"
/{
        aliases {
                spi_0    = &spi_0 ;
        };
        clocks{
                clk16m: oscillator {
                        #clock-cells = <0>;
                        compatible = "fixed-clock";
                        clock-frequency = <16000000>; //16MHz
                };
        };
        soc{
                spi_0: spi@f7106000 {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        can0: mcp2515@0 {
                                compatible = "microchip,mcp2515";
                                reg = <0>;
                                clocks = <&clk16m>;
                                interrupt-parent = <&gpio2>;
                                interrupts = <0 0x2>;
                                spi-max-frequency = <10000000>; //10 MHz
                        };
                };
        };
};

I am not completely sure that I have setup the interrupt pin correctly. The interrupt pin I am using is pin 23 on the lo-speed connector, GPIO2_0.

If anyone with more experience could have a look and let me know what could be wrong with this code, it would be much appreciated!

Hi,

I don’t have a CAN device to test, but have you rebuilt the kernel with the necessary configs for CAN enabled as modules?

CONFIG_CAN=m
CONFIG_CAN_RAW=m
CONFIG_CAN_BCM=m
CONFIG_CAN_GW=m
CONFIG_CAN_VCAN=m
CONFIG_CAN_DEV=m
CONFIG_CAN_CALC_BITTIMING=y
CONFIG_CAN_MCP251X=m