Running CAN-BUS Sample with different shield (NRF52840DK & Seeed CAN BUS Shield V2.0)

Hi All, 

Im very new to this how firmware space and would love some help.

Currently i have a NRF52840 DK Board with a Seeed Canbus shield. (CAN-BUS Shield V2.0 | Seeed Studio Wiki)

From what i have read is very similar to the DFROBOT CanBus Shield. (Only changing the default pinout for the CS from D10 to D9)

- I have been able to succesfully comple and flash the firmware but i get the following error :

Error starting CAN controller [-5]

I have tried modifying the dfrobot_can_bus_v2_0.overlay to make it work with my seeed shield.  (changing the CS-GPIOS to 15 (D9) instead of 16 (D10).

The error remains the same, and i dont really know how to get a little bit more information to progress on this.

Im trying to run this sample: zephyr/samples/drivers/can/counter at main · zephyrproject-rtos/zephyr (github.com)

  • Hi Efrain

    Error -5 means there is some communication issue with the board. 

    Do you know if the board is able to run at 3V? 
    The supply and GPIO voltage of the nRF52840DK is around 3V, while many Arduino shields require 5V supply. 

    Have you probed the SPI lines to see if there is any activity when the code runs? 
    If not it could point to some configuration issue in your project. 

    Could you share the overlay with me? 

    Best regards
    Torbjørn

  • Hi there,

    Thanks for the answer:

    I only changed the cs-pios to 15 to make it in line with the seeed information.

    /*
     * Copyright (c) 2019 Karsten Koenig
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    &arduino_spi {
    	status = "okay";
    	cs-gpios = <&arduino_header 15 GPIO_ACTIVE_LOW>; /* D9 */
    
    	mcp2515_dfrobot_can_bus_v2_0: can@0 {
    		compatible = "microchip,mcp2515";
    		spi-max-frequency = <1000000>;
    		int-gpios = <&arduino_header 8 GPIO_ACTIVE_LOW>; /* D2 */
    		status = "okay";
    		reg = <0x0>;
    		osc-freq = <16000000>;
    		bus-speed = <125000>;
    		sjw = <1>;
    		sample-point = <875>;
    
    		can-transceiver {
    			max-bitrate = <1000000>;
    		};
    	};
    };
    
    
    
    
    / {
    	chosen {
    		zephyr,canbus = &mcp2515_dfrobot_can_bus_v2_0;
    	};
    };

    I get the following logging info:

    [00:00:00.476,654] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    uart:~$ Error starting CAN control--- 431 messages dropped ---
    [00:00:00.499,145] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len 0x2000487f/1
    [00:00:00.499,176] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    [00:00:00.499,206] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len (nil)/0
    [00:00:00.499,237] <dbg> spi_nrfx_spi: finish_transaction: Transaction finished with status 0
    [00:00:00.499,389] <dbg> spi_nrfx_spi: spi_context_buffers_setup: tx_bufs 0x20004838 - rx_bufs 0x20004840 - 1
    [00:00:00.499,420] <dbg> spi_nrfx_spi: spi_context_buffers_setup: current_tx 0x20004848 (2), current_rx 0x20004858 (2), tx buf/len 0x20004834/2, rx buf/len (nil)/2
    [00:00:00.499,481] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/1
    [00:00:00.499,511] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len 0x2000487f/1
    [00:00:00.499,542] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    [00:00:00.499,572] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len (nil)/0
    [00:00:00.499,603] <dbg> spi_nrfx_spi: finish_transaction: Transaction finished with status 0
    [00:00:00.499,755] <dbg> spi_nrfx_spi: spi_context_buffers_setup: tx_bufs 0x20004838 - rx_bufs 0x20004840 - 1
    [00:00:00.499,786] <dbg> spi_nrfx_spi: spi_context_buffers_setup: current_tx 0x20004848 (2), current_rx 0x20004858 (2), tx buf/len 0x20004834/2, rx buf/len (nil)/2
    [00:00:00.499,847] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/1
    [00:00:00.499,877] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len 0x2000487f/1
    [00:00:00.499,908] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    [00:00:00.499,938] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len (nil)/0
    [00:00:00.499,969] <dbg> spi_nrfx_spi: finish_transaction: Transaction finished with status 0
    [00:00:00.500,122] <dbg> spi_nrfx_spi: spi_context_buffers_setup: tx_bufs 0x20004838 - rx_bufs 0x20004840 - 1
    [00:00:00.500,152] <dbg> spi_nrfx_spi: spi_context_buffers_setup: current_tx 0x20004848 (2), current_rx 0x20004858 (2), tx buf/len 0x20004834/2, rx buf/len (nil)/2
    [00:00:00.500,213] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/1
    [00:00:00.500,244] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len 0x2000487f/1
    [00:00:00.500,274] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    [00:00:00.500,305] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len (nil)/0
    [00:00:00.500,335] <dbg> spi_nrfx_spi: finish_transaction: Transaction finished with status 0
    [00:00:00.500,518] <dbg> spi_nrfx_spi: spi_context_buffers_setup: tx_bufs 0x20004838 - rx_bufs 0x20004840 - 1
    [00:00:00.500,549] <dbg> spi_nrfx_spi: spi_context_buffers_setup: current_tx 0x20004848 (2), current_rx 0x20004858 (2), tx buf/len 0x20004834/2, rx buf/len (nil)/2
    [00:00:00.500,579] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/1
    [00:00:00.500,610] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len 0x2000487f/1
    [00:00:00.500,640] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    [00:00:00.500,671] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len (nil)/0
    [00:00:00.500,701] <dbg> spi_nrfx_spi: finish_transaction: Transaction finished with status 0
    [00:00:00.500,885] <dbg> spi_nrfx_spi: spi_context_buffers_setup: tx_bufs 0x20004838 - rx_bufs 0x20004840 - 1
    [00:00:00.500,915] <dbg> spi_nrfx_spi: spi_context_buffers_setup: current_tx 0x20004848 (2), current_rx 0x20004858 (2), tx buf/len 0x20004834/2, rx buf/len (nil)/2
    [00:00:00.500,946] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/1
    [00:00:00.500,976] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len 0x2000487f/1
    [00:00:00.501,037] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    [00:00:00.501,037] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len (nil)/0
    [00:00:00.501,068] <dbg> spi_nrfx_spi: finish_transaction: Transaction finished with status 0
    [00:00:00.501,251] <dbg> spi_nrfx_spi: spi_context_buffers_setup: tx_bufs 0x20004838 - rx_bufs 0x20004840 - 1
    [00:00:00.501,281] <dbg> spi_nrfx_spi: spi_context_buffers_setup: current_tx 0x20004848 (2), current_rx 0x20004858 (2), tx buf/len 0x20004834/2, rx buf/len (nil)/2
    [00:00:00.501,312] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/1
    [00:00:00.501,342] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len 0x2000487f/1
    [00:00:00.501,403] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    [00:00:00.501,403] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len (nil)/0
    [00:00:00.501,434] <dbg> spi_nrfx_spi: finish_transaction: Transaction finished with status 0
    [00:00:00.501,617] <dbg> spi_nrfx_spi: spi_context_buffers_setup: tx_bufs 0x20004838 - rx_bufs 0x20004840 - 1
    [00:00:00.501,647] <dbg> spi_nrfx_spi: spi_context_buffers_setup: current_tx 0x20004848 (2), current_rx 0x20004858 (2), tx buf/len 0x20004834/2, rx buf/len (nil)/2
    [00:00:00.501,678] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/1
    [00:00:00.501,708] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len 0x2000487f/1
    [00:00:00.501,770] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    [00:00:00.501,770] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len (nil)/0
    [00:00:00.501,800] <dbg> spi_nrfx_spi: finish_transaction: Transaction finished with status 0
    [00:00:00.501,983] <dbg> spi_nrfx_spi: spi_context_buffers_setup: tx_bufs 0x20004838 - rx_bufs 0x20004840 - 1
    [00:00:00.502,014] <dbg> spi_nrfx_spi: spi_context_buffers_setup: current_tx 0x20004848 (2), current_rx 0x20004858 (2), tx buf/len 0x20004834/2, rx buf/len (nil)/2
    [00:00:00.502,075] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/1
    [00:00:00.502,105] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len 0x2000487f/1
    [00:00:00.502,136] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    [00:00:00.502,166] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len (nil)/0
    [00:00:00.502,197] <dbg> spi_nrfx_spi: finish_transaction: Transaction finished with status 0
    [00:00:00.502,349] <dbg> spi_nrfx_spi: spi_context_buffers_setup: tx_bufs 0x20004838 - rx_bufs 0x20004840 - 1
    [00:00:00.502,410] <dbg> spi_nrfx_spi: spi_context_buffers_setup: current_tx 0x20004848 (2), current_rx 0x20004858 (2), tx buf/len 0x20004834/2, rx buf/len (nil)/2
    [00:00:00.502,441] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/1
    [00:00:00.502,471] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len 0x2000487f/1
    [00:00:00.502,502] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    [00:00:00.502,532] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len (nil)/0
    [00:00:00.502,563] <dbg> spi_nrfx_spi: finish_transaction: Transaction finished with status 0
    [00:00:00.502,777] <dbg> spi_nrfx_spi: spi_context_buffers_setup: tx_bufs 0x20004838 - rx_bufs 0x20004840 - 1
    [00:00:00.502,807] <dbg> spi_nrfx_spi: spi_context_buffers_setup: current_tx 0x20004848 (2), current_rx 0x20004858 (2), tx buf/len 0x20004834/2, rx buf/len (nil)/2
    [00:00:00.502,838] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/1
    [00:00:00.502,868] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len 0x2000487f/1
    [00:00:00.502,899] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    [00:00:00.502,929] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len (nil)/0
    [00:00:00.502,960] <dbg> spi_nrfx_spi: finish_transaction: Transaction finished with status 0
    [00:00:00.503,112] <dbg> spi_nrfx_spi: spi_context_buffers_setup: tx_bufs 0x20004838 - rx_bufs 0x20004840 - 1
    [00:00:00.503,173] <dbg> spi_nrfx_spi: spi_context_buffers_setup: current_tx 0x20004848 (2), current_rx 0x20004858 (2), tx buf/len 0x20004834/2, rx buf/len (nil)/2
    [00:00:00.503,204] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/1
    [00:00:00.503,234] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len 0x2000487f/1
    [00:00:00.503,265] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    [00:00:00.503,295] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len (nil)/0
    [00:00:00.503,326] <dbg> spi_nrfx_spi: finish_transaction: Transaction finished with status 0
    [00:00:00.503,540] <dbg> spi_nrfx_spi: spi_context_buffers_setup: tx_bufs 0x20004838 - rx_bufs 0x20004840 - 1
    [00:00:00.503,570] <dbg> spi_nrfx_spi: spi_context_buffers_setup: current_tx 0x20004848 (2), current_rx 0x20004858 (2), tx buf/len 0x20004834/2, rx buf/len (nil)/2
    [00:00:00.503,601] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/1
    [00:00:00.503,631] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len 0x2000487f/1
    [00:00:00.503,662] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    [00:00:00.503,692] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len (nil)/0
    [00:00:00.503,723] <dbg> spi_nrfx_spi: finish_transaction: Transaction finished with status 0
    [00:00:00.503,875] <dbg> spi_nrfx_spi: spi_context_buffers_setup: tx_bufs 0x20004838 - rx_bufs 0x20004840 - 1
    [00:00:00.503,936] <dbg> spi_nrfx_spi: spi_context_buffers_setup: current_tx 0x20004848 (2), current_rx 0x20004858 (2), tx buf/len 0x20004834/2, rx buf/len (nil)/2
    [00:00:00.503,967] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/1
    [00:00:00.503,997] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len 0x2000487f/1
    [00:00:00.504,058] <dbg> spi_nrfx_spi: spi_context_update_tx: tx buf/len (nil)/0
    [00:00:00.504,089] <dbg> spi_nrfx_spi: spi_context_update_rx: rx buf/len (nil)/0
    [00:00:00.504,089] <dbg> spi_nrfx_spi: finish_transaction: Transaction finished with status 0
    [00:00:00.504,150] <err> can_mcp2515: Timeout trying to set MCP2515 operation mode
    [00:00:00.504,180] <err> can_mcp2515: Failed to set the mode [-5]
    uart:~$

    im not quite sure about the power question.  i have tried to put some extra sensors on the 3.3 output of the shield and that sensor works just fine. (but then again im guessing is just the direct line from the nrf).

  • Hi Efrain

    I checked the documentation for the shield closer and it seems it should be able to run both at 3.3V and at 5V. The MCP2515 supports a voltage range of 2.7-5.5V, so this makes sense. 

    Still, when I look at the schematic for the shield it seems the MCP2515 is powered by the 5V line:

    According to the specification for the MCP2515 the minimum value for an SPI high signal is 0.7*VDD = 3.5V (when supply is 5V).

    This means that when the nRF52840DK is running at ~3.0V supply the SPI signals will probably not be correctly received, unless there is some way to modify the shield to connect the MCP2515 to the 3.3V line rather than the 5V line. 

    Do you have a way of powering the nRF52840DK externally, such as a lab power supply? 
    If you could try to power the nRF52840DK through the external supply connector at 3.6V then the SPI signals should be compatible with the shield, even if the shield runs at 5V supply, and we can confirm once and for all if the SPI signal voltage is the issue. 

    Best regards
    Torbjørn

  • Hi,

    Shamefully i dont have a lab power supply.

    do you believe i could use an Arduino to power the Shield, and the connect the SPI lines to the NRF52?

    Something like:

    Arduino GND/V5  <--> Shield <--> sck,miso,mosi,cs

    Would that work? or the voltage difference might introduce an issue?

  • Hi Efrain

    I discussed this with a colleague, and as he pointed out you are not allowed to send signals to the nRF device with voltages higher than VDD + 0.3V, which means running the nRF at a lower voltage than the shield is not really recommendable. 

    I tried to find some documentation about converting the shield to run from the 3.3V line rather than the 5V line, but I couldn't really find anything. 

    You might be able to hack this yourself though, by cutting the 5V pin on the shield, and making a bridge from the 5V line to the 3.3V line. 

    As it happens I am doing some other works with CAN already and I am happy to order the shield and do some testing on my own, but this will take some time and I won't have any results to share for some weeks. If you need some results faster you would have to try it out on your own. 

    Best regards
    Torbjørn

Related