Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP32CAN.h>
- #include <CAN_config.h>
- // do not change the name!
- CAN_device_t CAN_cfg;
- void setup() {
- Serial.begin(115200);
- Serial.println("hello");
- CAN_cfg.speed=CAN_SPEED_1000KBPS;
- CAN_cfg.tx_pin_id = GPIO_NUM_5;
- CAN_cfg.rx_pin_id = GPIO_NUM_4;
- CAN_cfg.rx_queue = xQueueCreate(10,sizeof(CAN_frame_t));
- ESP32Can.CANInit();
- }
- void loop() {
- CAN_frame_t rx_frame;
- if(xQueueReceive(CAN_cfg.rx_queue,&rx_frame, 3 * portTICK_PERIOD_MS) == pdTRUE){
- if(rx_frame.FIR.B.FF == CAN_frame_std)
- Serial.println("New standard frame");
- else
- Serial.println("New extended frame");
- if(rx_frame.FIR.B.RTR == CAN_RTR){
- printf(" RTR from 0x%08x, DLC %d\r\n",rx_frame.MsgID, rx_frame.FIR.B.DLC);
- }else{
- printf(" from 0x%08x, DLC %d\n",rx_frame.MsgID, rx_frame.FIR.B.DLC);
- for(int i = 0; i < 8; i++){
- printf("%x ", rx_frame.data.u8[i]);
- }
- }
- Serial.println();
- }
- }
Add Comment
Please, Sign In to add comment