Proton BASIC Compiler - CAN commands

  • PicŪ Basic

  • CAN commands

    A library module for use with Library Manager by JohnGB. This module has been written by Bobby Garrett (RGV250 on PDS forum). The library module is offered on an as-is basis with no warranty as to its effectiveness, operation or reliability. Users use it at their own risk.

    This library provides a set of functions to configure and access the Microchip CAN module in selected PICŪ.

    The library was designed around the CAN module in 18F448/458, it also works in legacy mode(0) on newer PICŪ with ECAN modules (tested on 18F4680).


    The library consists of 10 commands of which most need to be used so I will be creating example code.

    • CAN Overview

    • CANInitialise - Initialises the CAN module
    • CANSetOperationMode - Sets the operating mode for the CAN module
    • CANSetMask - Used in conjunction with CANSetFilter
    • CANSetFilter - See CANSetMask
    • CANSetNodeID - Sets the node ID, must be unique to the network
    • CANSetMsgID - Used in conjunction with the Node ID to form the Identifier
    • CANSetBaudRate - Set all the parameters for communication
    • CANSendMessage - Formats Node/Msg ID and DATA for the CAN module to transmit
    • CANReceiveMessage - Returns with the Node/Msg ID and DATA for the current message
    • CANAbortAll - Cancels ALL pending messages

    • All code examples will be designed for 20Mhz xtal. - Do not use ceramic resonators.
    • The examples will be tested on 18F448 & 18F4680
    • Please note, the examples have only been tested on the latest beta release Support will only be given for that and later versions. The library will run on versions prior to this.
    • CAN connection sketch (hand drawn)
    • Simple periodic example
    • Simple event demo
    • Multiple messages demo
    • Expanding the network demo
    • Masks and Filters demo Future - Under construction
    • Changing the speed - Xtal & BUS - Under construction

    !!!Notes: Only Standard Identifiers have been catered for, if there is a demand for Extended Identifiers I will look into it. The Identifier consists of 5 bits for the NodeID which gives a max of 32 nodes and 6 bits are used for the MsgID giving a max of 64 messages.

    Remote transmit requests "RTR" have not been tested.

    I would like to thank JohnGB for his assistance in getting all this into a workable library and with some of the code.

    Download module

    Download ALL the library files including the CAN modules HERE
  • Recent Activity


    The Proton manual

    Thread Starter: towlerg

    I don't know if it's just me but I don't seem to be able to paste examples from the PDF. I'm sure I could at some time in the past but maybe I'm...

    top204 Yesterday, 17:19 Go to last post

    SD File System revisited

    Thread Starter: AlbertoFS

    I have reviewed the SD_File_System in a only checking all macros using the preprocessor too. I have tried to make the commands easier to...

    flosigud Yesterday, 18:53 Go to last post