Im working on a Ebike talaria MX4. im trying to get the can message using an arduino uno and a 8mhz mcp2515 board.
I have tried the loopback test on coryfowlr library and the autowp library. With the autowp library i couldnt get any messages. with the coryfowlr library i started getting messages right away but the data was partially incorrect. The weird part is i could only get data if i set my mcp2515 to 16MHZ in the startup code but the data was only partial right.
As of now i cant get any partial messages anymore they all corrupted data or if i set it to 8mhz i dont get any data at all. idk what im doing wrong im sure i have it wired correctly.
// CAN Receive Example
//
#include <mcp_can.h>
#include <SPI.h>
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
char msgString[128]; // Array to store serial string
String readString;
#define CAN0_INT 2 // Set INT to pin 2
MCP_CAN CAN0(10); // Set CS to pin 10
void setup()
{
Serial.begin(115200);
// Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
if (CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK)
Serial.println("MCP2515 Initialized Successfully!");
else
Serial.println("Error Initializing MCP2515...");
CAN0.setMode(MCP_LISTENONLY); // Set operation mode to normal so the MCP2515 sends acks to received data.
pinMode(CAN0_INT, INPUT); // Configuring pin for /INT input
Serial.println("MCP2515 Library Receive Example...");
}
void loop()
{
if (!digitalRead(CAN0_INT)) {
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if ((rxId & 0x80000000) == 0x80000000) { // Determine if ID is standard (11 bits) or extended (29 bits)
sprintf(msgString, "Standard ID: 0x%.3lX DLC: %1d Data:", rxId, len);
Serial.print(msgString);
}
Serial.println();
}
//
}
well machinna a0 and savvy can seem to read it just fine tho. sometimes it sort of work most other times the mcp2515 crashes after the first message. even if i remove the mcp2515 from the can bus it still spills random information in my serial console.
what i mean is, if i connect everything and im looking at the serial console it says its ready for a message, i turn on the key and can starts sending messages. the first message that arrives to the mcp2515 has invalid data and after that first message i get tons of false messages until i reset the arduino.
If you look at the MCP2515 datasheet you will see there are many settings that control how the chip behaves. Some of those settings will will result in a behavior that it outside the CAN bus 2.0b specification. For example, a CAN 2.0b compliant system uses ACK bits, but the Reddit post said that sending ACK bits caused problems.
That indicates there is something unusual with the way the Talaria is doing things. Effectively they have created their own proprietary version of a CAN bus which is not compatible with the CAN 2.0b specification.
but isnt ack only sent if in normal mode? im in ListenOnly mode. if i try to put it in normal mode it causes errors assuming because its sending acks from messages
I mean thats a good question, however with machinna a0 and savvycan the data appears to be correct i dont have an issue receiving messages, then when the arduino reader decides to try, the messages data is slightly wrong, the bytes 5-9 are right but the first half are wrong.
But most times the arduino reader dont work at all, causing some error on the first message that makes the serial print invalid things.
it might be a while be fore i get access to savvycan. i used the coryfowlr library and its the only one that would even sort of work. it worked for a few minutes, then after a while i started getting more and more bad data untill now it just errors as soon as it gets a message most times. It really seems like something is overflowing.
Or maybe some synchronization problems with the arudino and the mcp. the code dont actually use interrupts it seems. i couldnt find a way to make interrupts work.
If you are referring to a 16MHz Uno, then yes, it is too slow to receive all the messages on a busy 500k CAN bus. If you only need a subset of the messages, then setting up filters in the MCP2515 may help.
How are you powering the MCP2515 board?
The ESP32 uses 3.3v logic levels but Niren style 8MHz MCP2515 adaptors requires 5v, therefore you need to use level translators on the data pins going into the ESP32.
I was trying eith the arduino and 5v. I havnt had much luck so i tried the esp32 and collin80 ESP32CAN library. I setup the esp32 and connected the TJA1050 to the arduino. But when i run the canRecv code i dont see any messages. I checked the TJA1050 with a scope and i see signal to ESP32 but nothin happens in serial.
Im the mean time ive orderd some tja1051. I have confirmed the controller on the bike uses a 8mhz crystal and ata6561.
Any help getting any of this to work would be great.