Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
953 views
in Technique[技术] by (71.8m points)

raspberry pi3 - RaspberryPi 3b+ with multiple can buses (MPC2515))

I'm trying to connect 6 mcp2515 over spi0. I have adapted an SPI overlay to add the neccesary chip select lines. My new SPI overlay looks like this:

{
compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

fragment@0 {
    target = <&spi0>;
    frag0: __overlay__ {
        #address-cells = <1>;
        #size-cells = <0>;
        pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
        status = "okay";
        cs-gpios = <&gpio 8 1>, <&gpio 7 1>, <&gpio 22 1>, <&gpio 23 1>, <&gpio 24 1>, <&gpio 25 1>;

        spidev@0{
            compatible = "spidev";
            reg = <0>;  /* CE0 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
        };
        spidev@1{
            compatible = "spidev";
            reg = <1>;  /* CE1 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
        };
        spidev@2{
            compatible = "spidev";
            reg = <2>;  /* CE2 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
        };

        spidev@3{
            compatible = "spidev";
            reg = <3>;  /* CE3 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
        };
        spidev@4{
            compatible = "spidev";
            reg = <4>;  /* CE4 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
        };
        spidev@5{
            compatible = "spidev";
            reg = <5>;  /* CE5 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
        };
        
                    
    };
};

fragment@1 {
    target = <&gpio>;
    __overlay__ {
        spi0_cs_pins: spi0_cs_pins {
            brcm,pins = <7 8 22 23 24 25>;
            brcm,function = <1>; /* out */
        };
    };
};

With this SPI overlay i have the 6 spi's in /sys/bus/spi/devices/

spi0.0  spi0.1  spi0.2  spi0.3  spi0.4  spi0.5

I have also made new overlays for the mcp2515 (can0 to can5) in order to bind them with the new chip select lines of spi0.

My /boot/config.txt looks like this:

dtoverlay=spi-gpio-cs-new
dtoverlay=mcp2515-can0,oscillator=8000000,interrupt=5
dtoverlay=mcp2515-can4,oscillator=8000000,interrupt=26
dtoverlay=mcp2515-can5,oscillator=8000000,interrupt=27

dmesg | grep mcp

[    7.870207] mcp251x spi0.5 can0: MCP2515 successfully initialized.
[    7.892886] mcp251x spi0.4 can1: MCP2515 successfully initialized.
[    7.908725] mcp251x spi0.0 can2: MCP2515 successfully initialized.

ifconfig

can0: flags=193<UP,RUNNING,NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

can1: flags=193<UP,RUNNING,NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 36  bytes 180 (180.0 B)
        RX errors 0  dropped 36  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

can2: flags=193<UP,RUNNING,NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I only have 3 mcp2515 boards at my disposal for the moment. I have modified them regarding voltage supply to the CAN transceiver(5V) and can controller(3V) in order no to damage the Raspberry Pi GPIO's, the boards have been individually tested and I was able to send/receive CAN frames with them. They are connected to the Raspberry like this enter image description here

Out of these 3 interfaces only can1 (spi0.4) is working! Using candump I can see can frames on the network.

My question is why can0 and can2 are muted when trying to send or receive CAN messages (candump and cansend)?

Kernel interrupt table

CPU0       CPU1       CPU2       CPU3       
 17:        217          0          0          0  ARMCTRL-level   1 Edge      3f00b880.mailbox
 18:         47          0          0          0  ARMCTRL-level   2 Edge      VCHIQ doorbell
 40:          0          0          0          0  ARMCTRL-level  48 Edge      bcm2708_fb DMA
 42:        352          0          0          0  ARMCTRL-level  50 Edge      DMA IRQ
 44:       3062          0          0          0  ARMCTRL-level  52 Edge      DMA IRQ
 45:          0          0          0          0  ARMCTRL-level  53 Edge      DMA IRQ
 48:          0          0          0          0  ARMCTRL-level  56 Edge      DMA IRQ
 56:      14104          0          0          0  ARMCTRL-level  64 Edge      dwc_otg, dwc_otg_pcd, dwc_otg_hcd:usb1
 78:          0          0          0          0  ARMCTRL-level  86 Edge      3f204000.spi
 80:        158          0          0          0  ARMCTRL-level  88 Edge      mmc0
 81:       7450          0          0          0  ARMCTRL-level  89 Edge      uart-pl011
 86:       4207          0          0          0  ARMCTRL-level  94 Edge      mmc1
161:          0          0          0          0  bcm2836-timer   0 Edge      arch_timer
162:       1813       1900       2264       1528  bcm2836-timer   1 Edge      arch_timer
165:          0          0          0          0  bcm2836-pmu   9 Edge      arm-pmu
166:          0          0          0          0  lan78xx-irqs  17 Edge      usb-001:004:01
167:          0          0          0          0  pinctrl-bcm2835  26 Edge      spi0.5
168:          6          0          0          0  pinctrl-bcm2835  27 Edge      spi0.4
169:          0          0          0          0  pinctrl-bcm2835   5 Level     spi0.0
FIQ:              usb_fiq
IPI0:          0          0          0          0  CPU wakeup interrupts
IPI1:          0          0          0          0  Timer broadcast interrupts
IPI2:       1469       2966       3711       4460  Rescheduling interrupts
IPI3:        203        798        542        445  Function call interrupts
IPI4:          0          0          0          0  CPU stop interrupts
IPI5:         55         85         41         24  IRQ work interrupts
IPI6:          0          0          0          0  completion interrupts
Err:          0 

I can see from this table that the SPI's are assigned with interrupts but only spi0.4 is actually activated. How can activate the other 2 interrupts for spi0.0 and spi0.5?

question from:https://stackoverflow.com/questions/65680141/raspberrypi-3b-with-multiple-can-buses-mpc2515

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's working!!! As i mentioned in my first post only one board was working (can1 spi0.4), after i rechecked the other two non working boards i discovered that one had a hardware damage causing the other board not to work as well. As a final conclusion my spi and mcp overlays are fully functional!

Regards Antmar

 [    7.846788] mcp251x spi0.0 can0: MCP2515 successfully initialized.
 [    7.888039] mcp251x spi0.1 can1: MCP2515 successfully initialized.
 [    7.924747] mcp251x spi0.2 can2: MCP2515 successfully initialized.
 [    7.936608] mcp251x spi0.3 can3: MCP2515 successfully initialized.

can0  241   [5]  67 A4 31 F0 C7
can1  2A0   [2]  02 93
can2  241   [5]  67 A4 31 F0 CB
can3  240   [2]  02 6A

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...