电子说
CAN (controller Area Network):控制器局域网络总线,是一种有效支持分布式控制或实时控制的串行通信网络。
CAN在40PIN中的位置: CAN_TX对应40PIN中的第35编号,CAN_RX对应40PIN中的第12编号
CAN模块之间接线:CAN_TX接CAN_TX,CAN_RX接CAN_RX。
CONFIG_CAN=y
CONFIG_CAN_DEV=y
CONFIG_CAN_ROCKCHIP=y
CONFIG_CANFD_ROCKCHIP=y
cd kernel
make ARCH=arm64 menuconfig
make savedefconfig
kernel-5.10/arch/arm64/boot/dts/rockchip/rk3588s.dtsi
can0: can@fea50000 {
compatible = "rockchip,can-2.0";
reg = < 0x0 0xfea50000 0x0 0x1000 >;
interrupts = < GIC_SPI 341 IRQ_TYPE_LEVEL_HIGH >;
clocks = < &cru CLK_CAN0 >, < &cru PCLK_CAN0 >;
clock-names = "baudclk", "apb_pclk";
resets = < &cru SRST_CAN0 >, < &cru SRST_P_CAN0 >;
reset-names = "can", "can-apb";
pinctrl-names = "default";
pinctrl-0 = < &can0m0_pins >;
tx-fifo-depth = < 1 >;
rx-fifo-depth = < 6 >;
status = "disabled";
};
can1: can@fea60000 {
compatible = "rockchip,can-2.0";
reg = < 0x0 0xfea60000 0x0 0x1000 >;
interrupts = < GIC_SPI 342 IRQ_TYPE_LEVEL_HIGH >;
clocks = < &cru CLK_CAN1 >, < &cru PCLK_CAN1 >;
clock-names = "baudclk", "apb_pclk";
resets = < &cru SRST_CAN1 >, < &cru SRST_P_CAN1 >;
reset-names = "can", "can-apb";
pinctrl-names = "default";
pinctrl-0 = < &can1m0_pins >;
tx-fifo-depth = < 1 >;
rx-fifo-depth = < 6 >;
status = "disabled";
};
can2: can@fea70000 {
compatible = "rockchip,can-2.0";
reg = < 0x0 0xfea70000 0x0 0x1000 >;
interrupts = < GIC_SPI 343 IRQ_TYPE_LEVEL_HIGH >;
clocks = < &cru CLK_CAN2 >, < &cru PCLK_CAN2 >;
clock-names = "baudclk", "apb_pclk";
resets = < &cru SRST_CAN2 >, < &cru SRST_P_CAN2 >;
reset-names = "can", "can-apb";
pinctrl-names = "default";
pinctrl-0 = < &can2m0_pins >;
tx-fifo-depth = < 1 >;
rx-fifo-depth = < 6 >;
status = "disabled";
};
kernel-5.10/arch/arm64/boot/dts/rockchip/rk3588-armsom-w3.dts
/* can1 */
&can1 {
status = "okay";
assigned-clocks = < &cru CLK_CAN1 >;
assigned-clock-rates = < 200000000 >;
pinctrl-names = "default";
pinctrl-0 = < &can1m1_pins >; #根据原理图进行配置
};
ifconfig -a
ip link set can0 down //关闭CAN
ip link set can0 type can bitrate 500000 #设置⽐特率500KHz
ip -details -statistics link show can0 #打印can0信息
ip link set can0 up //启动CAN
cansend can0 123#DEADBEEF #发送(标准帧,数据帧,ID:123,date:DEADBEEF)
cansend can0 123#R #发送(标准帧,远程帧,ID:123)
cansend can0 00000123#12345678 #发送(扩展帧,数据帧,ID:00000123,date:DEADBEEF)
cansend can0 00000123#R #发送(扩展帧,远程帧,ID:00000123)
candump can0 //candump can0
审核编辑 黄宇
全部0条评论
快来发表一下你的评论吧 !