CAN Bus (aka Flex Bus)

Discussion in 'General Programming Discussion' started by Lifeboat_Jim, Oct 29, 2013.

  1. Lifeboat_Jim

    Lifeboat_Jim New Member

    Joined:
    Sep 16, 2013
    Messages:
    399
    Likes Received:
    1
    There are a couple of us interesting in using CAN Bus.

    As a pre-order I'm not expecting to get my boards for another 2-3 weeks, but I know they'll be some amongst the kickstarters who a) have their boards b) have an interest.

    Here is some info on getting it working (which is just a concise collection/summary from elsewhere):

    • The UDOO has a Flex Bus/CAN Bus *controller* (two actually) built in but it doesn't have the transceivers.
    • Having two controllers is really good because you can send on one and receive on the other and do some coding/testing 'easily'. These transceivers (The '234. the '233 which features 'loopback' isn't wanted as we have two busses & the '236 auto negotiates the speeds which sounds desirable but is a solution looking for a problem) are the ones to get I believe from my research so far.
    • There is at least one proven CAN library complete with demos for the Due already.
    • Schematic attached (from the thread linked below)

    • There is a most excellent (although long, and it goes back to the first steps) thread herecovering all of the above. Anyone who is interested really ought to read the whole thread.

    If anyone has any more info, please do reply with a concise summary and links.

    Cheers
     

    Attached Files:

  2. Reinhard

    Reinhard New Member

    Joined:
    Jun 25, 2013
    Messages:
    2
    Likes Received:
    0
    Hello,

    i have CAN running on my quad. I use the FlexCAN from the i.mx6 at the moment only.

    There are a few things to observe:

    1.) As much as i remember CAN-TX and CAN-RX are swapped, if you want to use CAN in the i.mx.
    2.) Load a sketch to the "DUE", to switch CAN-TX and CAN-RX pin's to input.
    3.) You had to recompile the linux kernel, to enable the CAN on the I/O pin's.

    If you have done this, gpsd read's nmea2000 messages from the CAN bus.

    I use a small PCB with the physical layer connected to an Aduino MEGA protoshield.

    Reinhard
     
  3. Reinhard

    Reinhard New Member

    Joined:
    Jun 25, 2013
    Messages:
    2
    Likes Received:
    0
    And here is the patch needed to enable the FlexCAN within the Linux Kernel.

    Reinhard

    Code:
    diff --git a/arch/arm/mach-mx6/board-mx6_seco_UDOO.c b/arch/arm/mach-mx6/board-mx6_seco_UDOO.c
    index 667313d..5186dfd 100644
    --- a/arch/arm/mach-mx6/board-mx6_seco_UDOO.c
    +++ b/arch/arm/mach-mx6/board-mx6_seco_UDOO.c
    @@ -910,7 +910,7 @@ static void __init mx6_seco_UDOO_board_init(void)
            imx_asrc_data.asrc_core_clk = clk_get(NULL, "asrc_clk");
            imx_asrc_data.asrc_audio_clk = clk_get(NULL, "asrc_serial_clk");
            imx6q_add_asrc(&imx_asrc_data);
    -      //  imx6q_add_flexcan0(&mx6q_sabrelite_flexcan0_pdata);
    +        imx6q_add_flexcan0(&mx6q_sabrelite_flexcan0_pdata);
    
            /* release USB Hub reset */
            gpio_set_value(MX6_UDOO_USB_HUB_RESET, 1);
    diff --git a/arch/arm/mach-mx6/board-mx6qd_seco_UDOO.h b/arch/arm/mach-mx6/board-mx6qd_seco_UDOO.h
    index 089a40b..ef10873 100644
    --- a/arch/arm/mach-mx6/board-mx6qd_seco_UDOO.h
    +++ b/arch/arm/mach-mx6/board-mx6qd_seco_UDOO.h
    @@ -360,10 +360,10 @@ static iomux_v3_cfg_t mx6qd_seco_UDOO_pads[] = {
                    // MX6Q_PAD_EIM_D24__UART3_TXD,
                    // MX6Q_PAD_EIM_D24__ECSPI1_SS2,
    
    -       MX6Q_PAD_GPIO_7__GPIO_1_7,                                                              // can tx
    -               // MX6Q_PAD_GPIO_7__CAN1_TXCAN,
    -       MX6Q_PAD_GPIO_8__GPIO_1_8,                                                              // can rx
    -               // MX6Q_PAD_GPIO_8__CAN1_RXCAN,
    +               // MX6Q_PAD_GPIO_7__GPIO_1_7,                                           // can tx
    +       MX6Q_PAD_GPIO_7__CAN1_TXCAN,
    +       //      MX6Q_PAD_GPIO_8__GPIO_1_8,                                              // can rx
    +        MX6Q_PAD_GPIO_8__CAN1_RXCAN,
     };
    
     static unsigned int mx6q_set_in_outputmode_low[] = {
    @@ -461,8 +461,8 @@ static unsigned int mx6q_set_in_inputmode[] = {
            MX6Q_PAD_EIM_CS0__GPIO_MODE,
            MX6Q_PAD_EIM_D24__GPIO_MODE,
    
    -       MX6Q_PAD_GPIO_8__GPIO_MODE,
    -       MX6Q_PAD_GPIO_7__GPIO_MODE,
    +//     MX6Q_PAD_GPIO_8__GPIO_MODE,
    +//     MX6Q_PAD_GPIO_7__GPIO_MODE,
     };
    
    
     
  4. Lifeboat_Jim

    Lifeboat_Jim New Member

    Joined:
    Sep 16, 2013
    Messages:
    399
    Likes Received:
    1
    Hi Reinhard

    Many thanks for the added information.

    Some more details could be useful I think, especially on what you've done on the physical side (what transceivers you choose, why, circuit diagrams, photos etc).

    Thanks also for the patch. That may be quite useful to some people. To reiterate this for others, remember that the GPIO's often have up to seven functions. Which pin has what function (such as SPDIF or CAN or GPIO etc) needs to be designated, and Reinhard's patch addresses that.
     
  5. kyleg

    kyleg New Member

    Joined:
    Dec 11, 2013
    Messages:
    5
    Likes Received:
    0
    To add info on the physical transciever I successfully used a TI SN65HVD230. These are the hookups to the board for 3.3v levels:
    UDOO, SN65HVD230
    J15 Pin7, Pin1
    J15 Pin8, Pin4
    J23 Pin4, Pin3
    J23 Pin7, Pin2 and Pin8

    Then the SN65HVD230 pins 6 and 7 go to the CAN bus and you should be good.

    For anyone interested I also made a script that updates the kernel in place on the standard ubuntu image (udoo_quad_ubuntu_1.3). It follows the official procedure pretty closely. I've only tested it on the quad. I also included a sketch to make the CAN pins inputs on the Arduino side. Both are attached.

    Warning: This procedure will overwrite your existing kernel, don't use it on anything but a fresh image. If anything goes wrong you may end up with an un-bootable system on your uSD card, so please read and understand the script before you run it.

    Directions: first download the udoo_quad_ubuntu_1.3.img file and image it to a uSD card per the official instructions. Next boot the board on that uSD card and then extract CanSupport.tar.gz to a suitable location such as your home folder. Then run the sketch. Open the serial monitor and make sure you can see the debug output to verify that it ran correctly. After that make sure you have internet access and then run the BuildKernel.sh script from the terminal with something like this:
    Code:
    sudo chmod +x BuildKernel.sh
    ./BuildKernel.sh
    
    Then the script will do the rest automatically, this could take a very long time depending mainly on the speed of the uSD card and your internet connection. It will do the following:
    1) Update the ubuntu install.
    2) Get the necessary compile tools.
    3) Download the kernel from github.
    4) Update the kernel source to enable the CAN.
    5) Compile the kernel.
    6) Overwrite the existing kernel.
    7) Update the /etc/network/interface to auto-start the can interface (this is where you modify the bitrate).
    8) Reboots the board.

    You will now have a can0 interface if you check with ifconfig. You can send a CAN packet with a command such as:
    Code:
    cansend can0 123#01.23.45.67.89.AB.CD.EF
    
     

    Attached Files:

  6. Lifeboat_Jim

    Lifeboat_Jim New Member

    Joined:
    Sep 16, 2013
    Messages:
    399
    Likes Received:
    1
    Thanks Kyleg, sounds spot on!

    I'll take a close look tonight.

    What's your own project?
     
  7. kyleg

    kyleg New Member

    Joined:
    Dec 11, 2013
    Messages:
    5
    Likes Received:
    0
    I'm prototyping the i.MX for internal control for a semiconductor test system that uses CAN. So far that's worked out well and the only bit of documentation I haven't seen is a parts list.
     
  8. oxoocoffee

    oxoocoffee Member

    Joined:
    Sep 13, 2016
    Messages:
    57
    Likes Received:
    6
    I did try to download attached CAN diagram and looks corrupt image. Can someone update this?
    CAN diagram.jpg
     

Share This Page