I’ve been trying to add support for CANBus to the tracker sample so I can gather some additional data and send it up with the location. I appended this into circuitdojo_feather_nrf9160_ns.overlay:

&spi2 {
        status = "okay";
        cs-gpios = <&feather_header 5 GPIO_ACTIVE_LOW>; /* CS */
        sck-pin = <&feather_header 6 >;
        mosi-pin = <&feather_header 7 >;
        miso-pin = <&feather_header 8 >;

        can1: mcp2515@0 {
                compatible = "microchip,mcp2515";
                spi-max-frequency = <1000000>;
                int-gpios = <&feather_header 4 GPIO_ACTIVE_LOW>;
                status = "okay";
                label = "CAN_1";
                reg = <0x0>;
                osc-freq = <8000000>;
                bus-speed = <500000>;
                sjw = <1>;
                prop-seg = <2>;
                phase-seg1 = <7>;
                phase-seg2 = <6>;
                #address-cells = <1>;
                #size-cells = <0>;
        };
};

/ {
        chosen {
                zephyr,can-primary = &can1;
        };
};

and I added to prj.conf:

CONFIG_CAN=y
CONFIG_CAN_INIT_PRIORITY=80
CONFIG_CAN_MAX_FILTER=5

When I call can_dev = device_get_binding(DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL) I get a NULL back. Does calling get_binding try to connect to the device, or is it just to get a handle? Anyone have any ideas what I might be doing wrong?

Using DEVICE_DT_GET is preferred over device_get_binding.

This is how I get it in my previously working/tested code:

const struct device *can_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_can_primary));

That doesn’t quite work either:

can_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_can_primary));"

zephyr/drivers/can/can_mcp2515.c:35:2: error: #error You must either set a sampling-point or timings (phase-seg* and prop-seg)
35 | #error You must either set a sampling-point or timings (phase-seg* and prop-seg)
| ^~~~~

But I have timings set in the device tree, as shown above. Zephyr is a complicated beast, and running down all the macro work it is up to is quite the challenge.

Looking at the source of that error:

#error You must either set a sampling-point or timings (phase-seg* and prop-seg)

#define SP_AND_TIMING_NOT_SET(inst) \
	(!DT_INST_NODE_HAS_PROP(inst, sample_point) && \
	!(DT_INST_NODE_HAS_PROP(inst, prop_seg) && \
	DT_INST_NODE_HAS_PROP(inst, phase_seg1) && \
	DT_INST_NODE_HAS_PROP(inst, phase_seg2))) ||

Looks like prop_seg can’t be found. Did you comment this out in your code? What version of Zephyr are you using? You may have to look at the mcp2515 samples in Zephyr to make sure your overlay entries jive with the samples.

Been playing with it and haven’t really made any progress. I’ve tried removing everything and slowly adding it back in. There isn’t any defines being added to the devicetree_unfixed.h for those elements (phase-seg and prop-seg) in the device tree.

The version of zephyr I’ve been using is whatever is installed by your VS-Code extension, I think. Looks like maybe that is 2.6.99? The extension for VSCode makes it easy to get started, but hard to understand what is actually going on in the background.

I tried installing the latest version from the zephyr-project’s github and working with that, and it seems like that might need to be a Nordic specific fork or Nordic modules to support the modem and GPS?

@mfarver There is no fixed version that is installed. It’s all based on the west manifest that you used to initialize your repo. Are you using the nFED repo or something else? I was using NCS v1.6.0 when I last played with this.

Here is an except from a working setup I had here not too long ago.

Overlay:

// Shared SPI bus for SD card and CAN
&spi2 {
    compatible = "nordic,nrf-spim";
    status = "okay";
    sck-pin = <19>;
	mosi-pin = <21>;
	miso-pin = <22>;
    cs-gpios = <&gpio0 18 GPIO_ACTIVE_LOW>, <&gpio0 17 GPIO_ACTIVE_LOW>;

    sdhc0: sdhc@0 {
        compatible = "zephyr,mmc-spi-slot";
        reg = <0>;
        status = "okay";
        label = "SDHC0";
        spi-max-frequency = <24000000>;
    };

    can1: mcp2515@1 {
        compatible = "microchip,mcp2515";
        spi-max-frequency = <1000000>;
        int-gpios = <&gpio0 16 GPIO_ACTIVE_LOW>;
        status = "okay";
        label = "CAN_1";
        reg = <0x1>;
        osc-freq = <16000000>;
        bus-speed = <125000>;
        sjw = <1>;
        prop-seg = <2>;
        phase-seg1 = <7>;
        phase-seg2 = <6>;
        #address-cells = <1>;
        #size-cells = <0>;
    };
};


/ {
    chosen {
        zephyr,can-primary = &can1;
    };
};

My config also enables the mcp2515 device. Are you doing that somewhere?

# Adding CAN
CONFIG_CAN=y
CONFIG_CAN_MCP2515=y
Terms and Conditions | Privacy Policy