Just started messing around with CAN on the ESP32....I designed my own PCB using an Infineon 3.3v CAN transceiver chip, assembled a prototype, and got it working perfectly! Many thanks to the excellent work of everyone involved in bringing the ESP32's internal CAN controller to life.
The one question I do have is regarding the libraries/formatting/syntax of how messages are sent within your code. I am using Arduino.
Right now, here is the test code that works perfectly
Code: Select all
my_frame.FIR.B.FF = CAN_frame_ext;
my_frame.MsgID = 291;
my_frame.FIR.B.DLC = 8;
my_frame.data.u8[0] = 7;
my_frame.data.u8[1] = 174;
my_frame.data.u8[2] = 6;
my_frame.data.u8[3] = 3;
my_frame.data.u8[4] = 0;
my_frame.data.u8[5] = 0;
my_frame.data.u8[6] = 127;
my_frame.data.u8[7] = 255;
ESP32Can.CANWriteFrame(&my_frame);
My question is, does anyone have input as far as making the above formatting/syntax more concise, such as modifying the ESP32 native CAN library to handle the message buffer as a single array?
The MCP2515 CAN SPI interface chip libraries are extremely concise and easy to use with global variables and byte arrays to hold the message.
Using the MCP2515 library is in the format of:
CAN.sendMsgBuf (CAN ID, std/ext ID, DLC length, message_bytes_array);
std (11bit) ID = 0
extended (29bit) ID = 1
So the MCP2515 equivalent of my ESP32 example above would be
Code: Select all
byte my_frame[8] = {8, 7, 174, 6, 3, 0, 0, 127, 255};
CAN.sendMsgBuf (291, 0, 8, my_frame);
Two lines of code, versus 12 lines of code.
I have a couple very large and complex CAN interface programs (2000+ lines of code) written for 8-bit AVR and MCP2515's that I am migrating over to the ESP32. It would be extremely nice to be able to tweak the ESP32 CAN libraries so they are compatible with my existing (MCP2515) programs.....rewriting the entire program to fit the ESP32's different CAN handling syntax.
two lines of code to send a message, and the ability to just leave all of the CAN messages at the beginning of the program in global variables is much easier to work with than using 12 lines of code to send the same message.
Especially since my project has 200 CAN messages stored in global variables used throughout the program...
Thanks