mirror of
https://github.com/Seeed-Studio/Seeed_Arduino_CAN.git
synced 2026-07-28 04:06:45 +00:00
@@ -0,0 +1,33 @@
|
|||||||
|
#include <SPI.h>
|
||||||
|
#include <mcp_can.h>
|
||||||
|
|
||||||
|
struct can_frame canMsg;
|
||||||
|
MCP_CAN mcp2515(10, MCP_CAN::MODE_NORMAL);
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
mcp2515.begin(CAN_125KBPS);
|
||||||
|
Serial.println("------- CAN Read ----------");
|
||||||
|
Serial.println("ID DLC DATA");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
if (mcp2515.readMessage(&canMsg) == MCP_CAN::ERROR_OK) {
|
||||||
|
|
||||||
|
Serial.print(canMsg.can_id); // print ID
|
||||||
|
|
||||||
|
Serial.print(canMsg.can_dlc); // print DLC
|
||||||
|
|
||||||
|
for (int i = 0; i<canMsg.can_dlc; i++) { // print the data
|
||||||
|
|
||||||
|
Serial.print(canMsg.data[i]);
|
||||||
|
Serial.print(" ");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user