Can bus issue , stuck messages
Posted: Mon Oct 07, 2019 2:17 pm
I have hit the limitation of what I could feel I could do with my Arduino Uno and I have moved to a shiny new ESP32. Almost everything worked immediately with very minor changes but I have encountered one issues that has me stumped.
Currently I have an ESP32 and an Arduino Uno connected to each other using two TJA1050 can bus transceivers.
The Uno is generating an sending messages using the following loop
On the receiving end the ESP32 uses the following code
This was previously working on the Arduino with out any issues.
But since moving to the ESP32 when I watch the logs the can bus transceivers connect, a message with each tag is received
but then it only ever spams the following log. The one can message that no longer adds up
If anyone has any suggestion as to what could cause this fault your help would be greatly appreciated.
Thank you for your time.
Currently I have an ESP32 and an Arduino Uno connected to each other using two TJA1050 can bus transceivers.
The Uno is generating an sending messages using the following loop
Code: Select all
void loop()
{
bar2 = bar2 +1;
if(bar2 == 10){
bar2 = 0;
bar1 = bar1 + 1;
}
if(bar1 == 10){
bar1 = 0;
}
unsigned char stmp[8] = {bar2, bar2, bar1, bar1, bar2, bar1, bar1, bar2};
CAN.sendMsgBuf(0x372, 0, 8, stmp);
delay(1000);
CAN.sendMsgBuf(0x368, 0, 8, stmp);
delay(1000);
CAN.sendMsgBuf(0x3E2, 0, 8, stmp);
delay(1000);
CAN.sendMsgBuf(0x3E0, 0, 8, stmp);
delay(1000); // send data per 500ms
}
Code: Select all
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <mcp_can.h>
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
#define SERIAL SerialUSB
#else
#define SERIAL Serial
#endif
const int SPI_CS_PIN = 2; // Defines the CS pin for the CAN interface
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
void setup(void) {
SERIAL.begin(115200); // Allows for the SERIAL data to be monitored over USB
while (CAN_OK != CAN.begin(CAN_1000KBPS))
{
SERIAL.println("CAN BUS Shield init fail");
SERIAL.println(" Init CAN BUS Shield again");
delay(100);
}
SERIAL.println("CAN BUS Shield init ok!");
}
void loop(void) {
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
unsigned long canId = CAN.getCanId();
SERIAL.println("-----------------------------");
SERIAL.print("CAN ID: 0x");
SERIAL.println(canId, HEX);
for(int i = 0; i<len; i++) // print the data
{
SERIAL.print(buf[i], HEX);
SERIAL.print("\t");
}
}
}
This was previously working on the Arduino with out any issues.
But since moving to the ESP32 when I watch the logs the can bus transceivers connect, a message with each tag is received
but then it only ever spams the following log. The one can message that no longer adds up
Code: Select all
01:02:45.458 -> CAN ID: 0x3E2
01:02:45.458 -> 1 1 0 0 1 0 0 1 -----------------------------
01:02:45.458 -> CAN ID: 0x3E2
01:02:45.458 -> 1 1 0 0 1 0 0 1 -----------------------------
01:02:45.458 -> CAN ID: 0x3E2
01:02:45.458 -> 1 1 0 0 1 0 0 1 -----------------------------
01:02:45.458 -> CAN ID: 0x3E2
01:02:45.458 -> 1 1 0 0 1 0 0 1 -----------------------------
01:02:45.458 -> CAN ID: 0x3E2
01:02:45.458 -> 1 1 0 0 1 0 0 1 -----------------------------
01:02:45.458 -> CAN ID: 0x3E2
01:02:45.492 -> 1 1 0 0 1 0 0 1 -----------------------------
01:02:45.492 -> CAN ID: 0x3E2
01:02:45.492 -> 1 1 0 0 1 0 0 1 -----------------------------
01:02:45.492 -> CAN ID: 0x3E2
01:02:45.492 -> 1 1 0 0 1 0 0 1 -----------------------------
01:02:45.492 -> CAN ID: 0x3E2
01:02:45.492 -> 1 1 0 0 1 0 0 1 -----------------------------
01:02:45.492 -> CAN ID: 0x3E2
If anyone has any suggestion as to what could cause this fault your help would be greatly appreciated.
Thank you for your time.