Created
October 8, 2020 15:31
-
-
Save jepler/d7b5a723ce59238a2db99b1bfe7f6cbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <Adafruit_ZeroCAN.h> | |
Adafruit_ZeroCAN can{}; | |
void setup() { | |
Serial.begin(9600); // open the serial port at 9600 bps: | |
digitalWrite(PIN_CAN_STANDBY, false); // turn off STANDBY | |
can.begin(1000000, true, false); | |
pinMode(A0, INPUT_PULLUP); | |
pinMode(A1, INPUT_PULLUP); | |
pinMode(A2, INPUT_PULLUP); | |
pinMode(13, OUTPUT); | |
} | |
Adafruit_ZeroCAN::Message m{0xaa, false, false, 8, {}}; | |
void loop() { | |
for(int j=0; ; j++) { | |
digitalWrite(13, j & 1); | |
for(int i = 0; i<64; i++) { | |
memset(&m.data, 0, sizeof(m.data)); | |
m.data[i/8] = 1<<(i % 8); | |
auto state = can.busState(); | |
if(state != Adafruit_ZeroCAN::ERROR_ACTIVE) { | |
Serial.print("bus state "); | |
Serial.println((int)state); | |
} | |
if(state == Adafruit_ZeroCAN::BUS_OFF) { | |
can.restart(); | |
} | |
can.send(m); | |
delay(1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment