AnsweredAssumed Answered

imx6ul mcp2515 diver

Question asked by 良杰 于 on Jul 3, 2016
Latest reply on Jul 4, 2016 by Rita Wang

1、电路

2016-07-03 21:40:51屏幕截图.png

2、管脚

      CS1-->GPIO4_IO28

      INT1-->GPIO5_IO02

      其他使用ECSPI2管脚

3、DTS配置

/{

...

        clocks {

                mcp251x_clock: mcp251x_clock {

                        compatible = "fixed-clock";

                        #clock-cells = <0>;

                        clock-frequency  = <8000000>;

                };

        };

...

};

 

&ecspi2 {

        compatible = "fsl,imx51-ecspi";

        fsl,spi-num-chipselects = <1>;

        cs-gpios = <0>;

        pinctrl-names = "default";

        pinctrl-0 = <&pinctrl_ecspi2>,<&pinctrl_ecspi2_cs>;

        status = "okay";

        can0: mcp2515@0 {

                compatible = "microchip,mcp2515";

                cs-gpios = <&gpio4 28 0>;

                reg = <0>;

                spi-max-frequency = <1000000>;

                clocks = <&mcp251x_clock>;

                interrupt-parent = <&gpio5>;

                interrupts = <2 0x2>;

                vdd-supply = <&reg_can_3v3>;

                xceiver-supply = <&reg_can_3v3>;

        };

 

};

&iomuxc{

                pinctrl_ecspi2: ecspi2grp{

                        fsl,pins = <

                                MX6UL_PAD_CSI_DATA00__ECSPI2_SCLK       0x100b1

                                MX6UL_PAD_CSI_DATA02__ECSPI2_MOSI       0x100b1

                                MX6UL_PAD_CSI_DATA03__ECSPI2_MISO       0x100b1

                        >;

                };

                pinctrl_ecspi2_cs: ecspi2csgrp {

                        fsl,pins = <

                                MX6UL_PAD_CSI_DATA07__GPIO4_IO28        0x80000000

                        >;

                };

};

 

4、Linux版本与配置

    linux-3.14.52

CONFIG_CAN=y

CONFIG_CAN_RAW=y

CONFIG_CAN_BCM=y

CONFIG_CAN_GW=y

 

 

#

# CAN Device Drivers

#

CONFIG_CAN_VCAN=y

# CONFIG_CAN_SLCAN is not set

CONFIG_CAN_DEV=y

CONFIG_CAN_CALC_BITTIMING=y

# CONFIG_CAN_LEDS is not set

# CONFIG_CAN_AT91 is not set

# CONFIG_CAN_TI_HECC is not set

CONFIG_CAN_MCP251X=y

CONFIG_CAN_FLEXCAN=y

# CONFIG_CAN_GRCAN is not set

# CONFIG_CAN_M_CAN is not set

# CONFIG_CAN_SJA1000 is not set

# CONFIG_CAN_C_CAN is not set

# CONFIG_CAN_CC770 is not set

 

5、启动log

启动脚本

/sbin/ifconfig can0 down

/sbin/ifconfig can1 down

/sbin/ifconfig can2 down

/sbin/ifconfig can0 txqueuelen 100

/sbin/ifconfig can1 txqueuelen 100

/sbin/ifconfig can2 txqueuelen 100

/sbin/ip link set can0 up type can bitrate 250000 restart-ms 10

/sbin/ip link set can1 up type can bitrate 250000 restart-ms 10

/sbin/ip link set can2 up type can bitrate 250000 restart-ms 10

log:

...

[    1.308895] spi_imx 200c000.ecspi: registered master spi1

[    1.309943] spi spi1.0: spi_imx_setup: mode 0, 8 bpw, 1000000 hz

[    1.309985] spi spi1.0: setup mode 0, 8 bits/w, 1000000 Hz max --> 0

[    1.310343] spi_imx 200c000.ecspi: registered child spi1.0

[    1.310376] spi_imx 200c000.ecspi: probed

[    1.317230] vcan: Virtual CAN interface driver

[    1.321717] CAN device driver interface

[    1.326035] mcp251x spi1.0: spi_imx_setup: mode 0, 8 bpw, 1000000 hz

[    1.326072] mcp251x spi1.0: setup mode 0, 8 bits/w, 1000000 Hz max --> 0

[    1.326498] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[    1.336678] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[    1.336855] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[    1.336983] mcp251x spi1.0: CANCTRL 0xe3

[    1.338271] mcp251x spi1.0: probed

[    1.344136] flexcan 2090000.can: gpr /soc/aips-bus@02000000/iomuxc-gpr@020e4000 req_gpr 0x10 req_bit 1 ack_gpr 0x10 ack_bit 17

[    1.344306] flexcan 2090000.can: device registered (reg_base=a0998000, irq=142)

[    1.353676] flexcan 2094000.can: gpr /soc/aips-bus@02000000/iomuxc-gpr@020e4000 req_gpr 0x10 req_bit 2 ack_gpr 0x10 ack_bit 18

[    1.353844] flexcan 2094000.can: device registered (reg_base=a09a0000, irq=143)

...

[   15.479788] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.489946] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.490078] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.490235] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.490364] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.490501] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.490627] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.490756] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.490869] mcp251x spi1.0: CNF: 0x00 0x00 0x00

[   15.495556] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.495692] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.495824] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.495950] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.496076] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.496205] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.496332] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.496460] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.509531] flexcan 2090000.can can1: writing ctrl=0x07292005

[   15.515520] flexcan 2090000.can can1: flexcan_set_bittiming: mcr=0x5980000f ctrl=0x07292005

[   15.515543] flexcan 2090000.can can1: flexcan_chip_start: writing mcr=0x7de2020d

[   15.515565] flexcan 2090000.can can1: flexcan_chip_start: writing ctrl=0x0729ac55

[   15.515602] flexcan 2090000.can can1: flexcan_chip_start: reading mcr=0x64e2020d ctrl=0x0729ac55

[   15.528534] flexcan 2094000.can can2: writing ctrl=0x07292005

[   15.534736] flexcan 2094000.can can2: flexcan_set_bittiming: mcr=0x5980000f ctrl=0x07292005

[   15.534765] flexcan 2094000.can can2: flexcan_chip_start: writing mcr=0x7de2020d

[   15.534786] flexcan 2094000.can can2: flexcan_chip_start: writing ctrl=0x0729ac55

[   15.534825] flexcan 2094000.can can2: flexcan_chip_start: reading mcr=0x64e2020d ctrl=0x0729ac55

 

6、当前问题

查看/sys/class/spi_master/已经注册成功。

使用cansend发送数据失败,接收数据失败。

将DTS配置成

&ecspi2 {

        compatible = "fsl,imx51-ecspi";

        fsl,spi-num-chipselects = <1>;

        cs-gpios = <0>;

        pinctrl-names = "default";

        pinctrl-0 = <&pinctrl_ecspi2>,<&pinctrl_ecspi2_cs>;

        status = "okay";

 

        spidev@0 {

                compatible = "spidev";

                spi-max-frequency = <10000000>;

                reg = <0>;

        };

};

使用spi_test测试,SPI输出脚有波形。

CAN总线总是不成功,收发都有问题。

是否有人碰到过类似的问题。帮忙解答一下。

Outcomes