Hello,
I am trying to set up the CAN bus on the ESP32 with the Arduino CAN library. It initializes ok but then it hangs on the writing of a message. Also receiving does not work. I can see with a LogicPro that the messages from a PCAN adapter are sent over the physical bus (CANH and CANL have proper levels and message is visible). But on the CANRX pin only the first few bits are present. Then out of some reason the CANRX stays high until the next message starts. So the messages are not propery passed on the the ESP32. And yes, the bus is terminated properly with 120 Ohms on each end.
If I only have the ESP32 side CAN tranceiver on the wire and send a message from the ESP32 and monitor the CANTX then the pattern does in no way resemble a CAN message at 250K baud. It just gives out pulses of 200µs and 8µs once and then hags in the CAN.endpacket().
So the CANL and CANH signal is ok, but anything that happens on CANRX or CANTX is garbage.
Here is my code:
#include <CAN.h>
void setup() {
Serial.begin(115200);
if (!CAN.begin(250E3))
{
LOGN("CAN BUS FAILED");
}else{
LOGN("CAN bus initialized");
}
}
void loop() {
CAN.beginPacket(0x10);
CAN.write(0xAA);
CAN.write(0xAA);
CAN.write(0xAA);
CAN.write(0xAA);
CAN.write(0xAA);
CAN.endPacket();
delay(500);
}
Any tips on whats going on here? I checked all my wiring with severel other tutorials I found. Using a SN65HVD231 and a TJA1042 both the same error. Pin 1 to ESP IO 5 and Pin 4 to ESP IO 4 of my ESP32 WROOM 32E. I used the canbus a dozen times with a STM32 without any trouble. I can not understand why this is not working.
Thanks for any tips. I will try to add some screenshots.
So I tryed pins 12 and 13 without luck. Then I used 4 and 5 again with the ESP32CAN. It works now. It seems it was not working because the baudrate is always half as what it is set to.
I looked at the CAN library. It says it does have support for the EPS's SJA1000 CAN controller. But the library produces no can messages. I need the callback functionality of the CAN library, which the ESP32CAN does not have. Why does the CAN library not work? anyone got an idea?
Thanks for the tip.
So end of the story is: my 3.3v CAN transeivers do not work at all (tried two different ones). And I had a bloody broken wire in the CAN bus. I hooked up a ADM3055 and that worked imediately flawlessly.