Mitchdetailed
Member
Greetings All! I'm working on a project of applying a standalone Engine Control and utilizing a Teensy for the OEM integration of Canbus information and am currently backtracking to understand either where I lack subject knowledge,
The aftermarket ecu has a limit up to 6 arbitration ID's sent and received, and 99 packets per Arbitration ID utilizing 7 bytes for actual data, with most parameters being user definable of variable start point, length, endian. Polling frequency can be ran at up to 200hz tx, no communicated limit on receiving data. The OEM ecu transmits 8 arbitration ID's and includes some parity bits, checksums, multipacket streams, etc. None of this really matters at this point and time, just an explanation of the big goal in hopes that I get led the right way towards it.
Since I lack a solid background in C++, I know i'm gonna have to take this 1 step at a time, I set up my hardware to a proper canbus bus topology utilizing 120ohm termination resistors, and tried to run the examples in the flexcan library, as well as the github library with no luck (tried them all minus the object oriented extended id's, as i'm only running standard id's. only the object oriented sent "something" as my car responded in a spastic manner, but nothing was showing on the bus network out of the norm, and also modified all of the example sketches to 500k as that's the vehicle's bus speed ) . I expect to be missing something in the code, just clueless as to where.
Platform is Windows10, Arduino IDE, with the Flexcan Library from Collin80 on Github. https://github.com/collin80/FlexCAN_Library
All help is appreciated and thank you in advance.
The aftermarket ecu has a limit up to 6 arbitration ID's sent and received, and 99 packets per Arbitration ID utilizing 7 bytes for actual data, with most parameters being user definable of variable start point, length, endian. Polling frequency can be ran at up to 200hz tx, no communicated limit on receiving data. The OEM ecu transmits 8 arbitration ID's and includes some parity bits, checksums, multipacket streams, etc. None of this really matters at this point and time, just an explanation of the big goal in hopes that I get led the right way towards it.
Since I lack a solid background in C++, I know i'm gonna have to take this 1 step at a time, I set up my hardware to a proper canbus bus topology utilizing 120ohm termination resistors, and tried to run the examples in the flexcan library, as well as the github library with no luck (tried them all minus the object oriented extended id's, as i'm only running standard id's. only the object oriented sent "something" as my car responded in a spastic manner, but nothing was showing on the bus network out of the norm, and also modified all of the example sketches to 500k as that's the vehicle's bus speed ) . I expect to be missing something in the code, just clueless as to where.
Platform is Windows10, Arduino IDE, with the Flexcan Library from Collin80 on Github. https://github.com/collin80/FlexCAN_Library
Code:
#include <FlexCAN.h>
#include <kinetis_flexcan.h>
// -------------------------------------------------------------
// CANtest for Teensy 3.6 dual CAN bus
// by Pawelsky (based on CANtest by teachop)
//
// This test transmits all data coming from CAN0 to CAN1 and vice versa (at 1Mbps)
//
#include <FlexCAN.h>
#ifndef __MK66FX1M0__
#error "Teensy 3.6 with dual CAN bus is required to run this example"
#endif
// modified file from 1m to 500kbps
FlexCAN CANbus0(500000);
FlexCAN CANbus1(500000);
static CAN_message_t msg;
static uint8_t hex[17] = "0123456789abcdef";
// -------------------------------------------------------------
static void hexDump(uint8_t dumpLen, uint8_t *bytePtr)
{
uint8_t working;
while( dumpLen-- ) {
working = *bytePtr++;
Serial.write( hex[ working>>4 ] );
Serial.write( hex[ working&15 ] );
}
Serial.write('\r');
Serial.write('\n');
}
// -------------------------------------------------------------
void setup(void)
{
CANbus0.begin();
CANbus1.begin();
// added code from line 41 to 46 ----------------------------
pinMode(28, OUTPUT);
pinMode(35, OUTPUT);
digitalWrite(28, LOW);
digitalWrite(35, LOW);
// added code from line 41 to 46 ----------------------------
delay(5);
Serial.println(F("Hello Teensy 3.6 dual CAN Test."));
}
// -------------------------------------------------------------
void loop(void)
{
if(CANbus0.available())
{
CANbus0.read(msg);
// Serial.print("CAN bus 0: "); hexDump(8, msg.buf);
CANbus1.write(msg);
}
if(CANbus1.available())
{
CANbus1.read(msg);
// Serial.print("CAN bus 1: "); hexDump(8, msg.buf);
CANbus0.write(msg);
}
}
All help is appreciated and thank you in advance.