Welcome to Bob & Eileen's web site. Bob generally blogs here while Eileen blogs over at her site. You can see our photos from here or click the little camera in the upper right corner.

Calendar

April 2024
S M T W T F S
 123456
78910111213
14151617181920
21222324252627
282930  

April 15, 2010

Overo + Controller Area Network

Filed under: Electronics,Robots,Software — Bob @ 7:20 pm

I’ve had a long interest in using Controller Area Network (CAN) to communicate between different components such as sensors or GPS modules or motor controllers. I wasn’t sure if I could do this with the Gumstix Overo board, but I got excited when I found out that Linux kernel version 2.6.33 would be including a driver for the Microchip MCP2515 CAN chip.

This required creating a custom image for the Overo, which meant setting up a build with OpenEmbedded. The Gumstix guys made it sound pretty easy in their instructions, so I set off to make it happen. I started with a virtual machine with Ubuntu 9.10 and set up bitbake and OpenEmbedded as suggested.

I’ve uploaded a tarball of my user.collection directory with overrides for the Overo machine configuration (you could probably ignore that) and for the Linux 2.6.33 recipe to include my configuration and patches to the Overo’s board initialization code for the MCP2515 chip on SPI bus 1 chip select 0.

My working environment for the org.openembedded.dev component uses change d535da0dfe20e965adb49d3acf720e7f9feb58c6. I’m sure by the time you try this there will be newer versions, but I can’t say whether my patches will work or not.

As for the hardware, the Overo uses 1.8v internally but the MCP2515 uses 5v. I used a few SparkFun logic level converter boards to translate voltages. Despite what you might read on their website, DO NOT USE the RX channels as this will send 2.5v into the 1.8v-capable pins on the Overo! Only use the TX channels (they are bidirectional and work at the correct voltage). I needed to translate five pins (SCLK, MISO, MISO, CS, and an interrupt pin) so I used three of the SparkFun boards.

I was able to use the candump program from the socket-can test tools suite to verify correct operation. Awesome!

19 Comments

  1. You didn’t have to make any changes to defconfig?

    Comment by Dat — August 2, 2010 @ 1:38 pm
  2. Hi Dat,

    Yes I definitely had to modify defconfig to include the right CAN modules. Have a look at ‘user.collection/recipes/linux/linux-omap3-2.6.33/overo/defconfig’ in the tarball.

    BTW I discovered today that I can’t transmit CAN messages with this build. I can receive messages just fine, but transmit doesn’t seem to work. Not sure yet how to resolve it.

    Comment by Bob — August 2, 2010 @ 5:16 pm
  3. Do you have to make a clone of the defconfig in your user.collection directory? I modified defconfig in the org.openembedded.dev directory but I don’t see the devices when i load it.

    Thanks.

    Comment by Dat — August 3, 2010 @ 11:31 am
  4. I am beginning to think my defconfig is being overwritten with the default settings. Do you know how I can tell if this is happening?

    Thanks.

    Comment by Dat — August 3, 2010 @ 11:32 am
  5. It is definitely possible that your defconfig file is being overwritten. It’s been a while since I last was working on this stuff (yesterday was the first time in several months) but as I recall I had to set up my own “linux” recipe in user.collection to entirely override the standard recipe.

    Unfortunately I’m not in front of the system for my embedded work right now but will be looking into it later to try to solve my problem transmitting packets. I’m going to try upgrading to a new kernel which means going through the whole thing again.

    Comment by Bob — August 3, 2010 @ 11:58 am
  6. Nevermind, my defconfig is not overwriting. I used this:
    #if defined(CONFIG_CAN_MCP251X)

    instead of:
    #if defined(CONFIG_CAN_MCP251X_MODULE)

    I think everything is good now. I will tell you if I have any luck with transmitting. Currently using 2.6.34 kernel.

    Comment by Dat — August 3, 2010 @ 1:10 pm
  7. By the way, do you have any example code to interface to the mcp2515 in user space for C?

    Thanks

    Comment by Dat — August 3, 2010 @ 1:15 pm
  8. What device name does mcp2515 register under?
    /dev/can0?

    Comment by Dat — August 3, 2010 @ 2:27 pm
  9. Once booted and mcp251x h/w is connected, run these commands as root:
    modprobe mcp251x
    ip link set can0 type can bitrate 125000
    ip link set can0 up

    If you want to see traffic on the bus, try this command:
    candump -a can0

    I used the sample code from the Wikipedia article as a quick how-to. The test programs in the socketcan distribution are also useful to read through.

    Comment by Bob — August 3, 2010 @ 4:40 pm
  10. I don’t have the mcp2515 yet. Is there a way for me to tell if I modified the kernel correctly to support the mcp2515?

    If modprobe mcp251x succeeds, will I see a device called ‘can0’ under /dev?

    Thanks.

    Comment by Dat — August 3, 2010 @ 7:44 pm
  11. Hi Dat,

    I doubt that will work. The initialization of the mcp251x driver will try to talk to the chip, and if it doesn’t find a valid response from the chip (over SPI) then it will fail to initialize.

    Comment by Bob — August 3, 2010 @ 8:57 pm
  12. Yeah thats what I’m seeing. I will try to connect the hardware tomorrow and retry the modprobe command.

    Comment by Dat — August 3, 2010 @ 8:58 pm
  13. I tried to send a can message with the cansend utility but it doesn’t work. I am able to receive can messages using candump. I am also seeing dropped frames and sometimes all zero frames. I don’t know why this is.

    Comment by Dat — August 11, 2010 @ 12:38 pm
  14. Sounds very similar to the problem I’ve been chasing. I believe the solution in my case is to change the GPIO pin for the interrupt line to “pull up” instead of down. I also found that slowing down the CAN bus and the SPI rate will improve reliability. I’m using 125kHz on the bus and a max of 500kHz for SPI.

    Comment by Bob — August 11, 2010 @ 1:36 pm
  15. […] while back I posted about my work to enable support for the Microchip MCP2515 CAN controller with my Gumstix Overo. At the time I was […]

    Pingback by random scribblings»Blog Archive » Overo + Controller Area Network (Revisited) — August 12, 2010 @ 7:37 pm
  16. I notice that in the mcp251x.c there is a variable for dma on/off: mcp251x_enable_dma. It is a module parameter but it seems to be read-only. Do you guys know if dma is even used?

    thanks.

    Comment by Dat — August 18, 2010 @ 7:14 pm
  17. Yeah I’ve noticed that but never tried turning it on. On the other hand, I suspect the SPI driver is using DMA anyways, based on some of the error messages it was generating. I don’t really know for certain though. It is probably worth trying to enable that switch and see what happens.

    Comment by Bob — August 18, 2010 @ 7:31 pm
  18. Bob,

    I set mcp251x_enable_dma to 1 with modprobe: ( modprobe mcp251x mcp251x_enable_dma=1 ). I am surprise that I was able to set it because isn’t S_IRUGO module parameter type read-only? Anyways, it did not give that much better performance if any.

    Comment by Dat — August 20, 2010 @ 5:53 am
  19. Hi Bob,

    can you post a schematic how you connected the mcp2515 and the gumstix overo board?

    Comment by Sven — September 1, 2010 @ 12:58 pm

Comments RSS

Sorry, the comment form is closed at this time.

Powered by: WordPress