大佬们,知道can能挂载但发送数据失败是有可能那些原因造成的
离线
你是用 spi nor flash 吗?
对的
离线
长夏十八 说:哇酷小二 说:你是用 spi nor flash 吗?
对的
那你的 mcp2515怎么挂的呢?
我的dts是这样写的
离线
使用示波器测了一下板子好像spi的时钟没反应
离线
不是说用spi flash吗? dts怎么没有看到呢?
在4楼发过了,不确定写的对不对,刚接触dts还不太熟练
离线
长夏十八 说:哇酷小二 说:不是说用spi flash吗? dts怎么没有看到呢?
在4楼发过了,不确定写的对不对,刚接触dts还不太熟练
是不是spi flash启动?
如果按四楼的 dts配置,应该不能启动,都没有spi flash配置。
spi flash启动?是指用TF卡吗,想问下spi flash的dts怎么配置,
离线
离线
参考这个blog: http://lnxpps.de/rpie/
首先确认硬件没问题,然后
本地回环测试:
# Maerklin Gleisbox (60112 and 60113) uses 250000
# loopback mode for testing
ip link set can0 up type can bitrate 125000 loopback on
日志应该是这样:
root@raspberrypi ~ # dmesg
[ 394.151290] bcm2708_spi bcm2708_spi.0: SPI Controller at 0x20204000 (irq 80)
[ 465.325599] can: controller area network core (rev 20090105 abi 8)
[ 465.325968] NET: Registered protocol family 29
[ 523.007604] CAN device driver interface
[ 560.310129] can: raw protocol (rev 20090105)
[ 565.070666] can: broadcast manager protocol (rev 20090105 t)
[ 593.259813] mcp251x spi0.0: CANSTAT 0x80 CANCTRL 0x07
[ 593.266881] mcp251x spi0.0: probed
[ 638.710821] mcp251x spi0.0: CNF: 0x03 0xb5 0x01
两机测试:
# on second terminal
root@raspberrypi ~ # candump any,0:0,#FFFFFFFF
can0 123 [4] DE AD BE EF
can0 123 [4] DE AD BE EF
can0 123 [4] DE AD BE EF
can0 123 [4] DE AD BE EF
root@raspberrypi ~ # cansend can0 123#deadbeef
root@raspberrypi ~ # cansend can0 123#deadbeef
root@raspberrypi ~ # ip -s -d link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10
link/can
can <LOOPBACK> state ERROR-ACTIVE restart-ms 0
bitrate 125000 sample-point 0.875
tq 500 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
clock 8000000
re-started bus-errors arbit-lost error-warn error-pass bus-off
0 0 0 0 0 0
RX: bytes packets errors dropped overrun mcast
8 2 0 0 0 0
TX: bytes packets errors dropped carrier collsns
8 2 0 0 0 0
看中断次数是否有增加:
root@raspberrypi ~# cat /proc/interrupts
CPU0
3: 192391 ARMCTRL BCM2708 Timer Tick
52: 2 ARMCTRL BCM2708 GPIO catchall handler
65: 2 ARMCTRL ARM Mailbox IRQ
66: 1 ARMCTRL VCHIQ doorbell
75: 14889016 ARMCTRL dwc_otg, dwc_otg_hcd:usb1
77: 11994 ARMCTRL bcm2708_sdhci (dma)
80: 58 ARMCTRL bcm2708_spi.0
83: 22 ARMCTRL uart-pl011
84: 21565 ARMCTRL mmc0
110: 2 GPIO mcp251x
Err: 0
我没有玩过can,上面是强行解释的,如有谬误,概不负责
离线
[ 1.107058] libphy: Fixed MDIO Bus: probed
[ 1.111186] CAN device driver interface
[ 2.136630] mcp251x spi0.1: MCP251x didn't enter in conf mode after reset
[ 2.143501] mcp251x spi0.1: Probe failed, err=16
[ 2.148280] mcp251x: probe of spi0.1 failed with error -16
V3s + MCP2515 这是什么问题呢?
离线
这是我的配置,仅供参考
硬件连接:
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 = <®_vcc5v0>;
xceiver-supply = <®_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
最近编辑记录 阿伟 (2022-10-25 16:16:41)
离线
最近在调这个,调出来了分享一下:)
有个关键点是需要5V供电,测试命令在buildroot配上iproute2和can-utils就能用了
内核就一项勾上就行,把设备树和测试命令放出来供参考
离线
Spi总线上挂有多个设备时要配置片选
离线