-
Notifications
You must be signed in to change notification settings - Fork 93
Description
I have no issues running my code at 125 K and all works great . The minute I run at 500 K my truck crashes .
I have all terminations done correctly and have termination resistors in place .
I was wondering if I had to play with TQ and sample points .
My truck seems to like 75 sample rate at 125 K speed .
It works perfect at 125K but i know the timing gets more critical the faster the bus speed .
Any help would be amazing .
Thanks
Here is my basic code .
//Reads all traffic on CAN0 and forwards it to CAN1 and modifies cluster frame first.
//Code based on samples provided by Thibaut Viard/Wilfredo Molina/Collin Kidder
//------------------------------------------------------------------------------------------------
// Required libraries
#include "variant.h"
#include <due_can.h>
//Leave defined if you use native port, comment if using programming port
//This sketch could provide a lot of traffic so it might be best to use the
//native port
#define Serial SerialUSB
void printFrame(CAN_FRAME *frame, int filter) {
Serial.print("Fltr: ");
if (filter > -1) Serial.print(filter);
else Serial.print("???");
Serial.print(" ID: 0x");
Serial.print(frame->id, HEX);
Serial.print(" Len: ");
Serial.print(frame->length);
Serial.print(" Data: 0x");
for (int count = 0; count < frame->length; count++) {
Serial.print(frame->data.bytes[count], HEX);
Serial.print(" ");
}
Serial.print("\r\n");
}
void gotFrame0(CAN_FRAME *frame)
{
//printFrame(frame, 1); //uncomment line to print frames that are going out
Can1.sendFrame(*frame);
}
void gotFrameCluster(CAN_FRAME *frame) //cluster
{
frame->data.byte[1]=0x08;
frame->data.byte[6]=0x01;
//printFrame(frame, 2); //uncomment line to print frames that are going out
Can1.sendFrame(*frame);
}
void gotFrame1(CAN_FRAME *frame)
{
//printFrame(frame, -1); //uncomment line to print frames that are going out
Can0.sendFrame(*frame);
}
void setup()
{
//Serial.begin(250000); //Uncomment for serial
// Initialize CAN0, Set the proper baud rates here
Can0.begin(CAN_BPS_500K);
// Initialize CAN1, Set the proper baud rates here
Can1.begin(CAN_BPS_500K);
//By default there are 7 RX mailboxes for each device - Standard frames
//Can0 Filters
Can0.setRXFilter(0, 0x372, 0x7FF, false); //Cluster
//Can1 Filters
Can1.setRXFilter(0, 0, false); //catch all mailbox - no mailbox ID specified
//now register all of the callback functions.
Can0.setCallback(0, gotFrameCluster);
//this function will get a callback for any mailbox that doesn't have a registered callback
Can0.setGeneralCallback(gotFrame0);
Can1.setGeneralCallback(gotFrame1);
}
void loop(){ //note the empty loop here. All work is done via callback as frames come in - no need to poll for them
}