ESP32_Arduino_CAN/examples/esp32can_receive/esp32can_receive.ino
2022-12-23 13:20:26 -05:00

27 lines
608 B
C++

#include <Arduino.h>
#include <ESP32CAN.h>
void setup() {
Serial.begin(115200);
Serial.println("ESP32-Arduino-CAN Receive Basic Demo");
ESP32Can.CANInit(GPIO_NUM_5, GPIO_NUM_4, ESP32CAN_SPEED_500KBPS);
}
void loop() {
twai_message_t rx_frame;
if (ESP32CAN_OK == ESP32Can.CANReadFrame(&rx_frame)) { /* CAN message received*/
Serial.print(rx_frame.identifier, HEX);
Serial.print(" ");
Serial.print(rx_frame.data_length_code);
for (int i=0; i<rx_frame.data_length_code; i++) {
Serial.print(rx_frame.data[i], HEX);
}
Serial.println();
}
delay(1000);
}