obus/debugging_tool/sketch_can_debugger/sketch_can_debugger.ino

28 lines
570 B
Arduino
Raw Normal View History

2020-08-19 02:10:30 +02:00
#include <mcp2515.h>
2020-09-07 21:23:39 +02:00
MCP2515 mcp2515(8);
2020-08-19 02:10:30 +02:00
void setup() {
Serial.begin(115200);
mcp2515.reset();
mcp2515.setBitrate(CAN_50KBPS);
mcp2515.setNormalMode();
2020-08-20 15:38:58 +02:00
for (int i = 0; i < 5; i++) {
Serial.println("begin");
delay(1000);
}
2020-08-19 02:10:30 +02:00
}
void loop() {
struct can_frame receive_frame;
if (mcp2515.readMessage(&receive_frame) == MCP2515::ERROR_OK) {
Serial.print("message ");
Serial.print(receive_frame.can_id, DEC);
2020-09-07 19:05:44 +02:00
for (int i = 0; i < receive_frame.can_dlc; i++) {
2020-08-19 02:10:30 +02:00
Serial.print(" ");
Serial.print(receive_frame.data[i], DEC);
}
Serial.print("\n");
}
}