Hi,
I hope this email finds you well. I am currently facing an issue with reading CAN data using a UART serial CAN Bus device, and I would greatly appreciate any assistance or insights you can provide.
In my code, I am sending the data using the system("cansend can0 7df#01020304")
command. I have verified that the data is being successfully received when using the candump can0
command with the Canable Pro device. However, when I attempt to read the same data using the UART serial CAN Bus device, I am not seeing any data.
Here is the code I have used for receiving the CAN frame:
#include <SPI.h>
#include "mcp_can.h"
#define SPI_CS_PIN 9
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
void setup()
{
Serial.begin(115200);
while(!Serial);
while (CAN_OK != CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("CAN BUS FAIL!");
delay(100);
}
Serial.println("CAN BUS OK!");
}
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
unsigned long canId = CAN.getCanId();
Serial.println("-----------------------------");
Serial.print("Get data from ID: ");
Serial.println(canId, HEX);
for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf[i], HEX);
Serial.print("\t");
}
Serial.println();
}
}
I would be grateful if anyone could provide some insights or suggestions on what might be causing this issue and how to resolve it. Additionally, if there are any specific settings or configurations that need to be considered when using a UART serial CAN Bus device, please let me know.
Thank you in advance for your help.
Thanks,
Vani