17.树莓派拓展板 =========================== 17.1 树莓派RS485/CAN拓展板 -------------------------- SC-3568HA不支持CAN通信,可以使用该拓展板通过SPI通讯来拓展出一路CAN。 拓展板实物图: |CAN_485| 拓展板引脚对照图: |CAN_485_1| 17.2 CAN通讯 -------------------------- 17.2.1 DTS配置 >>>>>>>>>>>>>>>>>>>>>>>>>> 该拓展板使用MCP2515来实现CAN通信,关于MCP2515的dts配置如下: .. attention:: 固件中没有适配MCP2515,若需要使用CAN接口,根据以下内容配置即可 + arch/arm64/boot/dts/rockchip/rk3568-toybrick-x0-linux.dts .. code-block:: c :linenos: / { mcp251x_clk: mcp251x-clk { compatible = "fixed-clock"; #clock-cells = <0>; clock-frequency = <12000000>; //根据MCP2515模块的硬件晶振设置 12MHz }; }; &spi3{ status = "okay"; pinctrl-0 = <&spi3m1_cs0 &spi3m1_pins>; pinctrl-1 = <&spi3m1_cs0 &spi3m1_pins_hs>; max-freq = <5000000>; mcp2515: mcp2515 { compatible = "microchip,mcp2515"; pinctrl-names = "default"; pinctrl-0 = <&mcp2515_irq1_pins>; reg = <0>; clocks = <&mcp251x_clk>; spi-max-frequency = <2000000>; interrupt-parent = <&gpio3>; interrupts = ; vdd-supply = <&vcc3v3_sys>; xceiver-supply = <&vcc3v3_sys>; status = "okay"; }; }; &pinctrl { mcp2515 { mcp2515_irq1_pins: mcp2515-irq1-pins { rockchip,pins = <3 RK_PB1 RK_FUNC_GPIO &pcfg_pull_none>; }; }; }; 17.2.1 CAN收发测试 >>>>>>>>>>>>>>>>>>>>>>>>>> 首先将拓展板与SC-3568HA板卡40PIN相连 连接如下图: |CAN_485_2| 17.2.1.1 回环测试 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 板卡带有CAN测试工具,连接好拓展板后输入命令测试 .. attention:: 1.回环测试无需连接CAN_H和CAN_L; 2.pin脚连接方式为一一对应,即1 pin脚对应拓展板1脚; 设置波特率以及回环模式: .. code-block:: bash :linenos: #将CAN0接口关闭 ip link set can0 down #设置比特率为 250000Hz,同时启用回环模式 ip link set can0 type can bitrate 250000 loopback on #将CAN0接口启用 ip link set can0 up 打开两个终端窗口,测试can0自收发: .. code-block:: bash :linenos: #终端1 candump can0 #终端2 cansend can0 -i 0x321 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 #或者只使用一个终端 candump can0 & cansend can0 -i 0x321 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 测试效果如下: + 终端1: |CAN_485_4| + 终端2: |CAN_485_5| 17.2.1.2 与CAN分析仪通信测试 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 将拓展板和分析仪进行连接。 |CAN_485_3| +----------+---------+ | 扩展板 |CAN分析仪| +==========+=========+ | CAN_H | CAN_H | +----------+---------+ | CAN_L | CAN_L | +----------+---------+ 设置波特率并进行测试 .. code-block:: bash :linenos: #将CAN0接口关闭 sudo ip link set can0 down #设置比特率为 250000 sudo ip link set can0 type can bitrate 250000 #将CAN0接口启用 sudo ip link set can0 up #发送(标准帧,数据帧,ID:7ff,date:11223344556677) cansend can0 -i 0x7ff 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 #接收 candump can0 + 终端测试效果: |CAN_485_6| + CAN分析仪测试效果: |CAN_485_7| 17.3 RS485 -------------------------- 该拓展板485支持自动切换收发状态,无需程序控制,只需将拓展板的8、10脚与SC-3568HA的40PIN的8、10脚相连,然后将485设备接上拓展板的A、B进行收发即可。 |CAN_485_8| .. |CAN_485| image:: picture/CAN_485.png .. |CAN_485_1| image:: picture/CAN_485_1.png .. |CAN_485_2| image:: picture/CAN_485_2.png :width: 6.22in :height: 4.02in .. |CAN_485_3| image:: picture/CAN_485_3.png :width: 6.22in :height: 4.02in .. |CAN_485_4| image:: picture/CAN_485_4.png :width: 7.22in :height: 1.702in .. |CAN_485_5| image:: picture/CAN_485_5.png :width: 7.22in :height: 1.702in .. |CAN_485_6| image:: picture/CAN_485_6.png :width: 7.22in :height: 2.02in .. |CAN_485_7| image:: picture/CAN_485_7.png .. |CAN_485_8| image:: picture/CAN_485_8.png