Skip to content

Instantly share code, notes, and snippets.

@illustris
Created June 2, 2017 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illustris/c76418202ad70449e4d0ffc3d40873dc to your computer and use it in GitHub Desktop.
Save illustris/c76418202ad70449e4d0ffc3d40873dc to your computer and use it in GitHub Desktop.
#include <FlexCAN.h>
#include <kinetis_flexcan.h>
int led = 13;
// create CAN object
FlexCAN CANReceiver(500000);
static CAN_message_t msg;
void setup() {
// init CAN bus
CANReceiver.begin();
pinMode(led, OUTPUT);
delay(1000);
Serial1.println("CAN Receiver Initialized");
}
void loop() {
while( CANReceiver.read(msg)) {
// toggle LEDs
digitalWrite(led, !digitalRead(led));
Serial1.print("Receiving: ");
for(int i=0; i<msg.len; i++) {
Serial1.print(msg.buf[i]); Serial1.print(" ");
}
Serial.println("");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment