nRF9160: MCP2515 SPI bus not ready

I am trying to use the MCP2515 SPI2CAN adapter with the nRF9160 DK. 

I started by trying to get the Zephyr socket_can sample to work. My efforts are based on this thread.

The problem is, that I am always getting an "SPI bus not ready" error from the can_mcp2515 driver. 

I successfully tested the SPI with a simple loopback example, so the overlay should be correct.

Here is my device tree overlay:

&spi3 {
    status = "okay";
    cs-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
	sck-pin = <10>;
	mosi-pin = <11>;
	miso-pin = <12>;	
  
    can1: mcp2515@0 {
      compatible = "microchip,mcp2515";
		spi-max-frequency = <1000000>;
		int-gpios = <&gpio0 31 GPIO_ACTIVE_LOW>;
		status = "okay";
		label = "CAN_1";
		reg = <0x0>;
		osc-freq = <10000000>;
		bus-speed = <1000000>;
		sjw = <1>;
		prop-seg = <2>;
		phase-seg1 = <7>;
		phase-seg2 = <6>;
		#address-cells = <1>;
		#size-cells = <0>;
    };
  };

  / {
	chosen {
		zephyr,canbus = &can1;
	};
};

prj.conf:

CONFIG_CAN=y
CONFIG_SPI=y
CONFIG_SPI_NRFX=y
CONFIG_CAN_MAX_FILTER=5
CONFIG_CAN_MCP2515=y
CONFIG_SPI_LOG_LEVEL_DBG=y

CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_CAN=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y

CONFIG_NET_IPV6=n
CONFIG_NET_IPV4=n
CONFIG_NET_MGMT=n
CONFIG_NET_TCP=n
CONFIG_NET_UDP=n

CONFIG_NET_DEFAULT_IF_CANBUS_RAW=y

CONFIG_NET_PKT_RX_COUNT=30
CONFIG_NET_PKT_TX_COUNT=30
CONFIG_NET_BUF_RX_COUNT=30
CONFIG_NET_BUF_TX_COUNT=30

CONFIG_TEST_RANDOM_GENERATOR=n

CONFIG_NET_SHELL=y
CONFIG_LOG=y
CONFIG_NET_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y

CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=y
CONFIG_CAN_LOG_LEVEL_DBG=y
#CONFIG_NET_CONTEXT_LOG_LEVEL_DBG=y
#CONFIG_NET_CORE_LOG_LEVEL_DBG=y
#CONFIG_NET_CONN_LOG_LEVEL_DBG=y

# Use smaller buffers for net_buf as CANBUS packets are quite small.
CONFIG_NET_BUF_DATA_SIZE=64

Output:

Parents
  • yavordobrev said:

    I am using NCS v1.9.1. The build errors have been resolved in this thread.

    It is suggested to edit zephyr/drivers/can/can_mcp2515.c, line 970, and replace the 1 with a 0.

    Ok, thanks Yavor! That being said, I should have read through the whole thread first ;-)

    The sample is failing at this point. When I debug into the function, the line below gives me the reason why it is failing. 

    I’m not sure why 'initialised' would be false here, as the devicetree should be configured correctly. But I do not have a MCP2515 available which I can connect to my DK, so possibly this might be required.  

    Otherwise, just for fault tracing, if you toggle the following lines: 

    // if (!spi_is_ready(&dev_cfg->bus)) { 
    // LOG_ERR("SPI bus %s not ready", dev_cfg->bus.bus->name); 
    // return -ENODEV; 
    // } 

    Does that make communication work, or do you end up in another fault?

    Regards, 

    Markus

Reply
  • yavordobrev said:

    I am using NCS v1.9.1. The build errors have been resolved in this thread.

    It is suggested to edit zephyr/drivers/can/can_mcp2515.c, line 970, and replace the 1 with a 0.

    Ok, thanks Yavor! That being said, I should have read through the whole thread first ;-)

    The sample is failing at this point. When I debug into the function, the line below gives me the reason why it is failing. 

    I’m not sure why 'initialised' would be false here, as the devicetree should be configured correctly. But I do not have a MCP2515 available which I can connect to my DK, so possibly this might be required.  

    Otherwise, just for fault tracing, if you toggle the following lines: 

    // if (!spi_is_ready(&dev_cfg->bus)) { 
    // LOG_ERR("SPI bus %s not ready", dev_cfg->bus.bus->name); 
    // return -ENODEV; 
    // } 

    Does that make communication work, or do you end up in another fault?

    Regards, 

    Markus

Children
Related