Core2 CAN-bus problem...



  • Hi,

    I want to do CAN communication using Core 2 and CAN Bus Unit (CA-IS3050G).

    I tried using the M5Stack example as a base, but it didn't work.

    It worked on Stick C +.
    Please let me know if you have any problems that I do not know.



  • Hello @hide4849

    the CAN bus unit uses a serial connection which by default is available on M5Stack Groove Port B. However M5Core2 (w/o M5GO battery bottom 2) only has a Port A which by default is used for I2C.

    So you either can try to reconfigure M5Core2 Port A from I2C to serial or stack an M5GO battery bottom 2 to your M5Core2 which then gives you Port B (and C).

    Thanks
    Felix



  • Hi, @felmue
    I remapped with this code but it didn't work.
    CAN_cfg.tx_pin_id = 32;
    CAN_cfg.rx_pin_id = 33;

    Is there any more other place to reconfigure?

    Thanks your reply.
    hide4849



  • Hello @hide4849

    you also need to make sure external I2C (using 32 and 33) does not get initialized, e.g. fourth parameter of M5.begin() should to be false (which is the default).

    Thanks
    Felix



  • Hi, @felmue

    I checked my code and it is false.
    M5.begin(true,false,true,false);

    It doesn't work even if all are false...
    M5.begin(false,false,false,false);

    It is the same even if all are true
    M5.begin(true,true,true,true);

    Thanks your reply.
    hide4849



  • Hello @hide4849

    sorry, I am out of ideas and I don't have the CAN-bus unit so I cannot test myself.

    Good luck!
    Felix



  • Anyone get any further on this? Tried the code below, which compiles and downloads, however I don't get any CANbus signals coming through. Not sure what else to check?


    #include <M5Core2.h>
    #include "CAN_config.h"
    #include "ESP32CAN.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

    uint8_t count = 0;

    void setup() {
    M5.begin(false,false,true,false); //(LCDEnable, SDEnable, SerialEnable, I2CEnable)
    CAN_cfg.speed = CAN_SPEED_250KBPS;
    CAN_cfg.tx_pin_id = GPIO_NUM_32;
    CAN_cfg.rx_pin_id = GPIO_NUM_33;
    CAN_cfg.rx_queue = xQueueCreate(rx_queue_size, sizeof(CAN_frame_t));
    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.RTR == CAN_RTR) {
      Serial.printf("RTR from 0x%08X, DLC %d\r\n", rx_frame.MsgID,  rx_frame.FIR.B.DLC);
    }
    else {
      Serial.printf("from 0x%08X, DLC %d, Data \r\n", rx_frame.MsgID,  rx_frame.FIR.B.DLC);
      for (int i = 0; i < rx_frame.FIR.B.DLC; i++) {
        Serial.printf("0x%02X ", rx_frame.data.u8[i]);
      }
      Serial.println("\n");
    }
    

    }
    }



  • I have the same problem. With Core or Core2 the CAN Unit is not working. I tried Port B and C (with Bottom/Bottom2). It even blocks CAN communication at my test setup (2 ESP32 development modules with additional SN65HVD230). If I use the same code with an Atom it works. Also the Atom CAN (basically the same as the CAN Unit) works with no problem. I also tried the sample code from m5Stack, doesn't work...

    The CAN Unit is not the problem. If I hook up a logic analyzer at the connection between Core and CAN Unit the data is fine.