您尚未登录。

#1 Re: 全志 SOC » v3s mcp2515 can能挂载不能收发数据 » 2022-10-25 16:11:02

这是我的配置,仅供参考

硬件连接:
V3S        MCP2515
SPI_SCK    ----->    CLK
SPI_MOSI    ----->    SI
SPI_MISO    ----->    SO
SPI_CS    ----->    CS
UART2_TX----->    INT
5V    ----->    5V
GND    ----->    GND
这里选用了UART2_TX引脚,也就是PB0引脚,作为模块的触发引脚。

我的模块用的是一个8M的晶振,所以在linux-zero-4.10.y/arch/arm/boot/dts/sun8i-v3s.dtsi文件里添加了一个8M的时钟(不知道是不是真的需要,反正是加上去了)

osc8M: osc8M_clk {
			#clock-cells = <0>;
			compatible = "fixed-clock";
			clock-frequency = <8000000>;
			clock-output-names = "osc8M";
		};

在linux-zero-4.10.y/arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dts中添加设备节点

&spi0 {
    	status = "okay";
    
    	can0: can@1 {
		compatible = "microchip,mcp2515";
		reg = <0>;
		clocks = <&osc8M>;
		interrupt-parent = <&pio>;
		interrupts = <1 0 IRQ_TYPE_LEVEL_LOW>; /* (PB0 */
		vdd-supply = <&reg_vcc5v0>;
		xceiver-supply = <&reg_vcc5v0>;
		spi-max-frequency = <2000000>;
	};
};

在menuconfig中添加驱动

[*]Networking support --->
    <*>CAN bus subsystem support --->
            CAN Device Drivers --->
	CAN SPI interfaces --->
	    <*>Microchip MCP251x SPI CAN controllers

这样系统在启动时就会打印模块加载成功的信息

[    0.770387] CAN device driver interface
[    0.785880] mcp251x spi32766.0 can0: MCP2515 successfully initialized.

配置一下之后can0也是能成功收到数据

root@licheepi:/home# ./ip link set can0 type can bitrate 500000 triple-sampling on
root@licheepi:/home# ifconfig can0 up
root@licheepi:/home# ifconfig
can0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          UP RUNNING NOARP  MTU:16  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:10
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

usb0      Link encap:Ethernet  HWaddr F2:84:B6:C6:77:AB
          inet addr:192.168.2.3  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

root@licheepi:/home# ./candump can0 &
root@licheepi:/home# interface = can0, family = 29, type = 3, proto = 1
<0x100> [8] 11 22 33 44 55 66 77 88
<0x100> [8] 11 22 33 44 55 66 77 88
<0x100> [8] 11 22 33 44 55 66 77 88
<0x100> [8] 11 22 33 44 55 66 77 88

我用的TF卡启动,没用spi flash,spi就只用做mcp2515

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn