ESP32 crash can bus communication with Arduino

Beubeu
Posts: 2
Joined: Thu Feb 09, 2023 9:23 am

ESP32 crash can bus communication with Arduino

Postby Beubeu » Thu Feb 09, 2023 9:37 am

Hello everyone,

I need to establish a Can bus link between an ESP32 and an Arduino Uno but my ESP32 crashes when launching the code.
The program uploads correctly but once in the monitor, it never reaches the loop and continuously redoes the setup.

Has anyone had this problem or knows how to fix it?


My code below:

Code: Select all

#define CAN_25KBPS          4 
#define CAN_50KBPS          8
#define CAN_125KBPS         13
#define CAN_500KBPS         16
#define CAN_1000KBPS        18

#define CAN_STDID          (0x00)
#define CAN_EXTID          (0x01)
#define CAN_STDID_REMOTE   (0x02)
#define CAN_EXTID_REMOTE   (0x03)



#include <Wire.h>
#include "Longan_I2C_CAN_Arduino.h"


#define I2C_1_SDA 41
#define I2C_1_SCL 40


I2C_CAN CAN(0x25);


void setup()
{

    Wire.begin(I2C_1_SDA, I2C_1_SCL);
    Serial.begin(115200);

    while (CAN_OK != CAN.begin(CAN_50KBPS)) 
    {
        Serial.println("CAN BUS FAIL!");
        delay(100);
    }
    Serial.println("CAN BUS OK!");

}

unsigned char buf[8] = {0, 1, 2, 3, 4, 5, 6, 0};
int incr = 0;

void loop()
{
    buf[7] = incr;
    incr = incr + 10;
    if(incr > 100)
    {
        incr = 0;
    }
    CAN.sendMsgBuf(0x01, CAN_STDID, 8, buf); // <- main suspect for the esp32 crash
    delay(100);
}

// END FILE
Attachments
Capture d’écran 2023-02-09 à 10.35.14.png
The monitor view
Capture d’écran 2023-02-09 à 10.35.14.png (230.3 KiB) Viewed 1403 times
Last edited by Beubeu on Fri Feb 10, 2023 2:57 pm, edited 1 time in total.

Beubeu
Posts: 2
Joined: Thu Feb 09, 2023 9:23 am

Re: ESP32 crash can bus communication with Arduino

Postby Beubeu » Fri Feb 10, 2023 2:56 pm

Ok in the library, there was just missing a "return 0;" :D
My code is all good but the
  1. sendMsgBuf
was wrong...

Never missed the return 0; if your function is not a void for ESP32 :p

Who is online

Users browsing this forum: No registered users and 55 guests