Hi Arduino team,
i encountered a problem while trying to receive CAN data via I2C. The following code is a demo code provided by Longan for the CAN I2C (Longan_I2C_Arduino Libray) . It worked fine with Arduino Uno but when i tested it with an ESP32 S3 WROOM, an error occurred.
links: GitHub - Longan-Labs/I2C_CAN_Arduino: Arduino Library for I2C CAN Bus Module
Code:
#define CAN_250KBPS
#include <Wire.h>
#include "Longan_I2C_CAN_Arduino.h"
I2C_CAN CAN(0x25); // Set I2C Address
void setup()
{
Serial.begin(115200);
//while(!Serial);
Wire.begin(19,20);
Serial.println("begin to init can");
while (CAN_OK != CAN.begin(CAN_250KBPS)) // init can bus : baudrate = 500k
{
Serial.println("CAN BUS FAIL!");
delay(100);
}
Serial.println("CAN BUS OK!");
pinMode(13, OUTPUT);
}
void loop()
{
unsigned char len = 0;
unsigned char buf[8];
if(CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming
{
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
if(len)
{
unsigned long canId = CAN.getCanId();
//Serial.print("Get ID: ");
Serial.print(canId, HEX);
Serial.print(" ");
for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf[i], HEX);
Serial.print("\t");
}
Serial.println();
}
}
delay(10);
blink();
}
void blink()
{
static unsigned long timer_s = millis();
if(millis()-timer_s < 100)return;
timer_s = millis();
digitalWrite(13, 1-digitalRead(13));
}
ERROR:
Guru Meditation Error: Core 1 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x420026f8: f665b24b 000000ff cb008136
Core 1 register dump:
PC : 0x420026fd PS : 0x00060530 A0 : 0x8200204d A1 : 0x3fca3760
A2 : 0x3fc98044 A3 : 0x3fca3783 A4 : 0x3fca3784 A5 : 0x00000000
A6 : 0x0000002b A7 : 0x3fca375f A8 : 0x820026fd A9 : 0x3fca3720
A10 : 0x00000001 A11 : 0x3fc98048 A12 : 0x3fca3783 A13 : 0x3fca3784
A14 : 0x3fca373c A15 : 0x3fca372c SAR : 0x00000000 EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000 LBEG : 0x40056f5c LEND : 0x40056f72 LCOUNT : 0xffffffff
Backtrace: 0x420026fa:0x3fca3760 0x4200204a:0x3fca3780 0x42005f3c:0x3fca37b0 0x4037ce46:0x3fca37d0
Thanks for your help!!