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