I can read DBC file and acquire/calculate both 11 and 29 but messages/signal. Send/receive PIDs including ISO TP with multiple modes (1, 9, 22) and so on.
I have GUI interface via BT 2.0 and Virtuino.
Now working on J1939 networking. Got the address claim down and working on the TP messages now.
Waiting for J1939 DBC with request messages (>8 byte messages for J1939).
for (i = 1; i < msg.len; i++){
msg.buf[i] = msg.buf[i+1];
}
msg.buf[0] = msg.buf[1];
Code:for (i = 1; i < msg.len; i++){ msg.buf[i] = msg.buf[i+1]; }
Code:msg.buf[0] = msg.buf[1];
msg.buf[7] = msg.buf[8];
for (i = 1; i < msg.len; i++){
msg.buf = msg.buf[i+1];
}
for (i = 0; i < msg.len -1; i++){
msg.buf[i] = msg.buf[i+1];
}
In file included from /Users/iuser/Desktop/CODE/sketch/config.h:19:0,
from /Users/iuser/Desktop/CODE/sketch/sketch.ino:16:
/Users/iuser/Desktop/CODE/sketch/src/drivers/tja1051/FlexCAN_T4.h:560:26: fatal error: FlexCAN_T4.tpp: No such file or directory
#include "FlexCAN_T4.tpp"
^
compilation terminated.
I wasn't expecting any problems. I have long-term experience with the SN65HVD230D chips and they're flawless.
Here's my setup. This is a custom PCB I made, which has dual TCAN330's. There are pins to pull SHDN/SILENT modes high or low (Teensy pins 2, 3).
The board has a jumper pad that should be cut to either control SHDN or S. I have not cut the trace, thinking I can just pull both low at the same time (maybe this is the mistake?).
I am using one of the examples sketches, just adding the pullup/down:
I am connecting to an 11B/250K CAN simulator. This is known working, tested with a different device.
I'm using CAN2 (pins 0, 1), pulling the appropriate function pin low (sleepPin1), but not getting anything at all from the Teensy. I have also tried removing the 120ohm resistor.
sleepPin2 is high to disable CAN1 (22, 23). I have a common ground with the simulator.
Any ideas are greatly appreciated.
View attachment 24320
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_256> Can0;
void setup(void) {
Serial.begin(115200); delay(400);
pinMode(2, OUTPUT); digitalWrite(2, LOW); // enable tranceiver
pinMode(3, OUTPUT); digitalWrite(3, LOW); // enable tranceiver
delay(1000);
Can0.begin();
//Can0.setClock(CLK_24MHz);
Can0.setBaudRate(250000);
Can0.setMaxMB(16); // up to 64 max for T4, not important in FIFO mode, unless you want to use additional mailboxes with FIFO
Can0.enableFIFO();
Can0.enableFIFOInterrupt();
Can0.onReceive(canSniff);
Can0.mailboxStatus();
}
void canSniff(const CAN_message_t &msg) {
Serial.print("MB "); Serial.print(msg.mb);
Serial.print(" OVERRUN: "); Serial.print(msg.flags.overrun);
Serial.print(" LEN: "); Serial.print(msg.len);
Serial.print(" EXT: "); Serial.print(msg.flags.extended);
Serial.print(" TS: "); Serial.print(msg.timestamp);
Serial.print(" ID: "); Serial.print(msg.id, HEX);
Serial.print(" Buffer: ");
for ( uint8_t i = 0; i < msg.len; i++ ) {
Serial.print(msg.buf[i], HEX); Serial.print(" ");
} Serial.println();
}
void loop() {
Can0.events();
static uint32_t timeout = millis();
if ( millis() - timeout > 1000 ) { // send random frame every 20ms
CAN_message_t msg;
msg.id = random(0x1,0x7FE);
for ( uint8_t i = 0; i < 8; i++ ) msg.buf[i] = i + 1;
Can0.write(msg);
timeout = millis();
Can0.mailboxStatus();
}
}
FIFO Enabled --> Interrupt Enabled
FIFO Filters in use: 8
Remaining Mailboxes: 8
MB8 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x76D)(Payload: 1 2 3 4 5 6 7 8)
MB9 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x4BC)(Payload: 1 2 3 4 5 6 7 8)
MB10 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x489)(Payload: 1 2 3 4 5 6 7 8)
MB11 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x599)(Payload: 1 2 3 4 5 6 7 8)
MB12 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x151)(Payload: 1 2 3 4 5 6 7 8)
MB13 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x5F2)(Payload: 1 2 3 4 5 6 7 8)
MB14 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x641)(Payload: 1 2 3 4 5 6 7 8)
MB15 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0xC6)(Payload: 1 2 3 4 5 6 7 8)
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> canbus;
CAN_message_t msg;
void setup(void) {
pinMode(2, OUTPUT);
digitalWrite(2, LOW); // enable tranceiver
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
delay(500);
canbus.begin();
canbus.setBaudRate(500000);
canbus.setMaxMB(16); // up to 64 max for T4, not important in FIFO mode, unless you want to use additional mailboxes with FIFO
canbus.enableFIFO();
canbus.enableFIFOInterrupt();
canbus.onReceive(canSniff);
canbus.mailboxStatus();
Serial.println("CAN Test");
}
void canSniff(const CAN_message_t &msg) {
static uint32_t timeout = millis();
Serial.print("MB "); Serial.print(msg.mb);
Serial.print(" OVERRUN: "); Serial.print(msg.flags.overrun);
Serial.print(" LEN: "); Serial.print(msg.len);
Serial.print(" EXT: "); Serial.print(msg.flags.extended);
Serial.print(" TS: "); Serial.print(timeout);
Serial.print(" ID: "); Serial.print(msg.id, HEX);
Serial.print(" Buffer: ");
for ( uint8_t i = 0; i < msg.len; i++ ) {
Serial.print(msg.buf[i], HEX); Serial.print(" ");
} Serial.println();
timeout = millis();
digitalWrite(13, HIGH);
digitalWrite(13, LOW);
}
void loop() {
canbus.events();
static uint32_t timeout = millis();
if ( millis() - timeout > 49 ) { // send random frame every 20ms
CAN_message_t msg;
msg.id = random(0,0);
for ( uint8_t i = 0; i < 8; i++ ) msg.buf[i] = i + 1;
canbus.write(msg);
timeout = millis();
}
}
honestly, single shot mode in "flexcan" hardware, this is it's behaviour. i spent alot of time on that debugging and really the only way to stop it is by manually aborting, which, you'd have to handle all on your own (or alternatively reconfigure the mailbox woth setMB), however you will still need to tepp your code to stop sending if that is your goal. this loops you round circles. another alternate way is to just deassert the transceiver and force aborts, stop sending, but then you'd not get traffic activity to get out of bus off without reasserting the transceiver. But yes, bus off on flexcan hardware puts all transmissions in retry attempt, not once only.
EDIT: alternatively we can switch to listen only mode until the bus off state recovers? I did add error reporting recently, perhaps that may be of assistance?