Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <mcp_can.h>
- #include <SPI.h>
- const int SPI_CS_PIN = 10;
- MCP_CAN CAN(SPI_CS_PIN);
- void setup() {
- Serial.begin(115200);
- while (CAN_OK != CAN.begin(CAN_500KBPS)) {
- Serial.println("CAN BUS Shield init fail");
- delay(100);
- }
- Serial.println("CAN BUS Shield init ok!");
- }
- void loop() {
- unsigned char len = 0;
- unsigned char buf[8];
- if (CAN_MSGAVAIL == CAN.checkReceive()) {
- CAN.readMsgBuf(&len, buf);
- Serial.print("Message received: ");
- for (int i = 0; i < len; i++) {
- Serial.print((char)buf[i]);
- }
- Serial.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement