Skip to content

This is a library to connect the SAMC21 to a CAN bus.

License

Notifications You must be signed in to change notification settings

hugllc/samc21_can

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Main Page

Introduction

This library is for connecting a SAMC21 to a CAN bus using the Arduino or PlatformIO build environments. It is made to be compatible with MCP_CAN_lib (https://github.com/coryjfowler/MCP_CAN_lib) so that I can create a single library that uses either depending on what processor is being used on the project.

Requirements

SAMC support is still not in the mainline samd (Arduino or platformio). SAMC support is available for Arduino here:

https://github.com/prices/ArduinoCore-samd

For platformio it is available here:

https://github.com/prices/platform-atmelsam

Using the Library

Platformio

Installing

platformio platform install https://github.com/prices/platform-atmelsam

platformio.ini Example

[platformio]
env_default = samc21

[env:samc21]
platform = atmelsam
framework = arduino
board = samc21_xpro

lib_deps = https://github.com/hugllc/samc21_can.git

Code

Then for the code

#include <samc21_can.h>

SAMC21_CAN can(0);

void setup()
{
    uint8_t ret;
    ret = can.begin(MCP_ANY, CAN_125KBPS, MCP_8MHZ);
    if (ret == CAN_OK) {
        Serial.println("CAN Initialized Successfully!");
    } else {
        Serial.println("Error Initializing CAN...");
    }
}

void loop()
{
    uint8_t ret;
    uint32_t id;
    uint8_t len;
    uint8_t buf[8];
    uint8_t i;
    
    ret = can.readMsgBuf(&id, &len, buf);
    if (ret == CAN_OK) {
        Serial.print("Got a message from: ");
        Serial.print(id);
        Serial.print("  Length: ");
        Serial.print(len);
        Serial.print("  Data: ");
        for (i = 0; i < len; i++) {
            Serial.print(buf[i], HEX);
        }
        Serial.println("");
    }
}

License

LGPL V3

Acknowledgements

The API was copied from https://github.com/coryjfowler/MCP_CAN_lib, as well as the constant files mcp_can_dfs.h. Other things might be from there, also.

About

This is a library to connect the SAMC21 to a CAN bus.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published