ESP32 Missing CAN Frames

ssm3e30
Posts: 1
Joined: Sun Jan 09, 2022 12:49 am

ESP32 Missing CAN Frames

Postby ssm3e30 » Sun Jan 09, 2022 1:02 am

Hi,

Background
I am using a Lolin32 board to read CAN BUS data from a Megasquirt ECU. I am using the ESP32CAN.h library (https://github.com/miwagner/ESP32-Arduino-CAN) with a SN65HVD230 transceiver and have gotten it to successfully read in the CAN data and output to a display or serial monitor. I have used the basic example code in the library.

Issue
The problem is I can only receive frame from 1 message ID. The CAN data supplied by the Megasquirt is outputting with decimal message IDs from 1512 to 1516, however in the serial monitor the ESP32 is only receiving data for ID 1512. I do not have any active filters. I know the data supplied from the Megasquirt can have varying IDs, because I can turn them on and off. If I turn one off another will show, but never more than 1 simultaneously.

Help welcome to investigate why this is happening.

ESP32 Code:

Code: Select all

#include <Arduino.h>
#include <ESP32CAN.h>
#include <CAN_config.h>

CAN_device_t CAN_cfg;               // CAN Config
unsigned long previousMillis = 0;   // will store last time a CAN Message was send
const int interval = 1000;          // interval at which send CAN Messages (milliseconds)
const int rx_queue_size = 10;       // Receive Queue size

void setup() {
  Serial.begin(2000000);
  Serial.println("Basic Demo - ESP32-Arduino-CAN");
  CAN_cfg.speed = CAN_SPEED_500KBPS;
  CAN_cfg.tx_pin_id = GPIO_NUM_22;
  CAN_cfg.rx_pin_id = GPIO_NUM_21;
  CAN_cfg.rx_queue = xQueueCreate(rx_queue_size, sizeof(CAN_frame_t));
  // Init CAN Module
  ESP32Can.CANInit();

}

void loop() {

    
  CAN_frame_t rx_frame;

  unsigned long currentMillis = millis();

  // Receive next CAN frame from queue
  if (xQueueReceive(CAN_cfg.rx_queue, &rx_frame, 3 * portTICK_PERIOD_MS) == pdTRUE) {

    if (rx_frame.FIR.B.FF == CAN_frame_std) {
      printf("New standard frame");
    }
    else {
      printf("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, Data ", rx_frame.MsgID,  rx_frame.FIR.B.DLC);
      
      //ID Bit
      Serial.println(rx_frame.MsgID);

      //Number of Bytes
      Serial.println(rx_frame.FIR.B.DLC);

      
      
      //Print byte 0
      Serial.println(rx_frame.data.u8[7], HEX);

      //Print byte 1
      Serial.println(rx_frame.data.u8[1], HEX);

      //Combine bytes 0 and 1
      float combine = ((int)rx_frame.data.u8[0] << 8) | rx_frame.data.u8[1];
      combine = combine/10;
      Serial.println(combine);
      
      for (int i = 0; i < rx_frame.FIR.B.DLC; i++) {
        printf("0x%02X ", rx_frame.data.u8[i]);
      }
      printf("\n");
    }
  }
}
Output:

Code: Select all

New standard frame from 0x000005E8, DLC 8, Data 0x03 0x61 0x00 0x00 0x07 0x08 0x0A 0x38 
1512
8
38
61
86.50
New standard frame from 0x000005E8, DLC 8, Data 0x03 0x61 0x00 0x00 0x07 0x08 0x0A 0x38 
1512
8
38
61
86.50
New standard frame from 0x000005E8, DLC 8, Data 0x03 0x61 0x00 0x00 0x07 0x08 0x0A 0x38 
1512
8
38
61
86.50
New standard frame from 0x000005E8, DLC 8, Data 0x03 0x61 0x00 0x00 0x07 0x08 0x0A 0x38 
1512
8
38
61
86.50
New standard frame from 0x000005E8, DLC 8, Data 0x03 0x61 0x00 0x00 0x07 0x08 0x0A 0x38 
1512
8
38
61
86.50
New standard frame from 0x000005E8, DLC 8, Data 0x03 0x61 0x00 0x00 0x07 0x08 0x0A 0x38 
1512
8
38
61
86.50
New standard frame from 0x000005E8, DLC 8, Data 0x03 0x61 0x00 0x00 0x07 0x08 0x0A 0x38 
Additional CAN Data being broadcast:
2022-01-08 18_00_50-Megasquirt_CAN_Broadcast.pdf.png
2022-01-08 18_00_50-Megasquirt_CAN_Broadcast.pdf.png (141.22 KiB) Viewed 3490 times

jblazeg
Posts: 3
Joined: Wed May 25, 2022 7:55 am

Re: ESP32 Missing CAN Frames

Postby jblazeg » Sun Feb 05, 2023 10:49 am

any solution in this?

Who is online

Users browsing this forum: Google [Bot] and 59 guests