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).

    Syntax

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

    • CAN Overview


    !!!Operators
    • 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

    Examples
    • 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 3.3.4.8. 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