Connect with us

PIC CAN bus for automation, existing or custom library?

Discussion in 'Microcontrollers, Programming and IoT' started by Simy, Sep 2, 2013.

Scroll to continue with content
  1. Simy


    Aug 23, 2013
    Ok basically the short and skinny is I have an RV/bus conversion and need to rewire it. I figure I would do so and use CAN so I can later do some pretty neat things but I've been having lots of problems. I don't wan't peer to peer networking like is offered with J1939 because I will have 3-4 nodes that control the exterior lights and I don't want to have to control them one at a time. I want to be able to plug a new module in without recoding the entire system. Canopen seems ok but the two libraries ive been trying to use I continue to have problems with (I've tried canopennode and AN945 from microchip) I don't want to reinvent the wheel but I want a higher level of abstraction then they offer and I also don't like the way that things are organized.

    What I envisioned when I first started learning about CAN and canopen is a file that is something like this:
    #define _LIGHTS 	0x100D		//in order: Not used, Marker, Left turn, Right turn, Backup, Headlights, Highbeams, Brake
    #define _DRIVETRAIN_CMD 0x100F		//in order: 0-3 unused, Ignition, start, Gear up, Gear down
    #define _GEAR 		0x1010 		//Single byte where 0 = error, 1 = Reverse, 2 = Neutral 3=Drive, 4=1st, 5=2nd, etc

    By grouping things intelligently I can use filters/masks to ignore nodes that don't matter. For example the Nodes that control the lights shouldn't care what the RPM is.
    Whenever a new byte of lights was received (which would be on timer and or change) I would update what the current lights are doing. When it came to the engine the start value that would time out after say 2 seconds. Just in case we don't get another packet.

    A heartbeat of some kind can be sent from every node, on a specific band range of ID's, If the Nodes function is mostly output. However if its putting information into the system I can just use the timer and or on change model and make sure it sends updated data every so often to know if it is alive.

    That right there sums up what I would do, and I believe I would learn a great deal just looking into writing this backend, my question however is am I reinventing the wheel (specifically canopen)? This is the simplest library/system for me to achieve what I want now, but I have gone down this road in the past and basically ended up rewriting the library I wasn't going to use because it was overly complicated. Typically that means I'm just tired of banging my head up against the wall trying to get it to work and this is one of those times. I have spent the better part of 3 months trying to figure this out and I don't have anything to produce other then frustration.

    Sorry for the long post, but any other comments and let me know if I should stick with canopennode, if you know of another option that I might want or if my idea of a custom solution seems sound and is worth pursuing. Thanks.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day