CAN开启后是否可以直接连接CAN设备

  • 您好,Luckfox Lyra 的引脚只输入输出逻辑电平,还需要使用CAN收发器将逻辑电平转换成CAN总线所需的差分电平信号
  • Crocodile wrote: 2025-05-29 6:15 您好,Luckfox Lyra 的引脚只输入输出逻辑电平,还需要使用CAN收发器将逻辑电平转换成CAN总线所需的差分电平信号
    WIK里面说可以直接连接USB-CAN-A. 那么电平匹配吗?
  • wiki 说明以 USB-CAN-A 为基础进行测试,Luckfox Lyra输出的是数字信号,和USB-CAN-A的主控 STM32 以及其他主控芯片一样需要经过类似https://www.waveshare.net/shop/SN65HVD230-CAN-Board.htm的转换模块才能输出差分信息进行CAN通讯。
    想要省略掉转换模块就需要直接连接电平输出标准相同的主控,比如两个Luckfox Lyra的CAN引脚直接连接,但这也失去了CAN通讯的优势不如选用其他协议。
  • Crocodile wrote: 2025-06-03 6:26 wiki 说明以 USB-CAN-A 为基础进行测试,Luckfox Lyra输出的是数字信号,和USB-CAN-A的主控 STM32 以及其他主控芯片一样需要经过类似https://www.waveshare.net/shop/SN65HVD230-CAN-Board.htm的转换模块才能输出差分信息进行CAN通讯。
    想要省略掉转换模块就需要直接连接电平输出标准相同的主控,比如两个Luckfox Lyra的CAN引脚直接连接,但这也失去了CAN通讯的优势不如选用其他协议。
    明白了,谢谢
  • 抱歉还要请教,我已经外接了CAN收发器,但是发现无法通讯,can分析仪发送和接收都无法通过,有什么排查手段吗?
    CAN收发模块的TX接Lyra的GPIO1_D2, RX接Lyra的GPIO1_D3. 再接上3.3V供电。

    我的CAN设备配置如下:
    &can0 {
    assigned-clocks = <&cru CLK_CAN0>;
    assigned-clock-rates = <200000000>;
    pinctrl-names = "default";
    pinctrl-0 = <&rm_io30_can0_tx &rm_io31_can0_rx>;
    status = "okay";

    };


    外部收发模块如下:
    Image
    Last edited by xlh145 on 2025-06-03 7:04, edited 1 time in total.
  • 先不连接模块短接GPIO1_D2,GPIO1_3 进行回环测试确定配置生效,信号输出没有问题,再连接CAN转换模块与can分析仪进行通讯测试
  • Crocodile wrote: 2025-06-03 7:39 先不连接模块短接GPIO1_D2,GPIO1_3 进行回环测试确定配置生效,信号输出没有问题,再连接CAN转换模块与can分析仪进行通讯测试
    GPIO1_D2,GPIO1_D3 短接,CAN配置如下:
    ip link set can0 down
    ip link set can0 type can bitrate 1000000 dbitrate 1000000 fd on
    ip link set can0 up


    然后开俩个终端,其中一个终端运行:candump can0 监听can报文, 另外一个终端运行:cansend can0 123##1DEADBEEF
    然后发现第一个终端并没有数据打印

    然后我用ip -details link show can0 查看,发现状态是ERROR-ACTIVE,这是配置有问题吗?

    root@luckfox:~# ip -details link show can0
    2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
    link/can promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
    can <FD> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
    bitrate 1003102 sample-point 0.744
    tq 10 prop-seg 36 phase-seg1 36 phase-seg2 25 sjw 1 brp 2
    rk3576_canfd: tseg1 1..128 tseg2 1..128 sjw 1..128 brp 1..256 brp_inc 2
    dbitrate 1003102 dsample-point 0.714
    dtq 71 dprop-seg 4 dphase-seg1 5 dphase-seg2 4 dsjw 1 dbrp 14
    rk3576_canfd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..256 dbrp_inc 2
    clock 196608000 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 parentbus platform parentdev ff320000.can
    Last edited by xlh145 on 2025-06-03 8:28, edited 1 time in total.
  • 回环测试的命令如下

    Code: Select all

    ip link set can0 down
    ip link set can0 type can bitrate 1000000 dbitrate 1000000 fd on #速度要低于设备树设置的 assigned-clock-rates
    ip link set can0 type can loopback on
    ip link set can0 up
    
    
     candump can0 & #后台接收
     cansend can0 123#DEADBEEF 
    
  • 开启lookback是可以收发,这个没问题。但是不开启lookback,把GPIO1_D2和GPIO1_D3短接(不使用外部CAN收发器)发现无法测试通过。配置如下:

    Code: Select all

    ip link set can0 down
    ip link set can0 type can bitrate 1000000 dbitrate 1000000 fd on 
    ip link set can0 up
     candump can0 & #后台接收
     cansend can0 123#DEADBEEF 
    
    终端log如下:

    Code: Select all

    root@luckfox:~# ip link set can0 down
    root@luckfox:~# ip link set can0 type can bitrate 1000000 dbitrate 1000000 fd on
    root@luckfox:~# ip link set can0 up
    root@luckfox:~# candump can0 &
    [1] 1903
    root@luckfox:~# cansend can0 123#DEADBEEF
    root@luckfox:~# cansend can0 123#DEADBEEF
    root@luckfox:~# cansend can0 123#DEADBEEF
    root@luckfox:~# cansend can0 123#DEADBEEF
    root@luckfox:~#