// Copyright (c) Sandeep Mistry. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. #include uint8_t CanB[8]; // Name of the array and size void setup() { Serial.begin(115200); while (!Serial); Serial.println("CAN Receiver"); CAN.setClockFrequency(8E6); CAN.setPins(9, 2); // start the CAN bus at 250 kbps if (!CAN.begin(250E3)) { Serial.println("Starting CAN failed!"); while (1); } CAN.filter(0x212); } void loop() { // try to parse packet int packetSize = CAN.parsePacket(); if (packetSize) { // received a packet Serial.print("Received "); if (CAN.packetExtended()) { Serial.print("extended "); } if (CAN.packetRtr()) { // Remote transmission request, packet contains no data Serial.print("RTR "); } Serial.print("packet with id 0x"); Serial.print(CAN.packetId(), HEX); if (CAN.packetRtr()) { Serial.print(" and requested length "); Serial.println(CAN.packetDlc()); } else { Serial.print(" and length "); Serial.println(packetSize); // only print packet data for non-RTR packets //CAN.readBytes(CanB, 8); while (CAN.available()) { for (int i = 0; i < packetSize; i++) { CanB[i] = CAN.read(); Serial.print(CanB[i]); Serial.print(" "); } } Serial.print("First complete Val: "); int16_t r = (CanB[1]<<8) | CanB[0]; Serial.println(r); } Serial.println(); } }