From 219fffb5e576dbdbe8af7ea451b64e7d63196762 Mon Sep 17 00:00:00 2001 From: Sam Perry <17242713+sdp8483@users.noreply.github.com> Date: Tue, 13 Dec 2022 20:02:31 -0500 Subject: [PATCH] new examples --- .../esp32can_receive/esp32can_receive.ino | 27 ++++++++++++++++ examples/esp32can_send/esp32can_send.ino | 32 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 examples/esp32can_receive/esp32can_receive.ino create mode 100644 examples/esp32can_send/esp32can_send.ino diff --git a/examples/esp32can_receive/esp32can_receive.ino b/examples/esp32can_receive/esp32can_receive.ino new file mode 100644 index 0000000..a8538f9 --- /dev/null +++ b/examples/esp32can_receive/esp32can_receive.ino @@ -0,0 +1,27 @@ +#include +#include + +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; + + ESP32Can.CANReadFrame(&rx_frame); + + Serial.print(rx_frame.identifier, HEX); + Serial.print(" "); + Serial.print(rx_frame.data_length_code); + + for (int i=0; i +#include + +void setup() { + Serial.begin(115200); + Serial.println("ESP32-Arduino-CAN Send Basic Demo"); + + ESP32Can.CANInit(GPIO_NUM_5, GPIO_NUM_4, ESP32_SPEED_500KBPS); +} + +void loop() { + twai_message_t tx_frame; + + tx_frame.extd = 0; + tx_frame.data_length_code = 8; + tx_frame.identifier = 0x123; + + tx_frame.data[0] = 0xDE; + tx_frame.data[1] = 0xAD; + tx_frame.data[2] = 0xBE; + tx_frame.data[3] = 0xEF; + tx_frame.data[4] = 0xBA; + tx_frame.data[5] = 0x5E; + tx_frame.data[6] = 0xBA; + tx_frame.data[7] = 0x11; + + ESP32Can.CANWriteFrame(&tx_frame); + + Serial.println("CAN Frame Sent"); + + delay(1000); +}