@jim lee: Sorry, I don't have any personal experience with the Adafruit device. The CANbus interface that I used was ordered from Amazon (it was a SN65HVD230 breakout), however, it is no longer available. Based upon the fact that the Waveshare device is using the same SN65HVD230 primary IC, I would think that it should work as well.Would this work? Adafruit can bus interface
Or possibly this one? Waveshare SN65HVD230 - Found on Amazon.
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can0;
You can find an explanation here. (From Google Search)Ok I'm assuming this : FlexCAN_T4 is the library I want to use for this "TJA1051" board. This says it it goof for Teensy 4.0 processors.
The way the example creates the instance of the interface :Code:FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can0;
I'm not familiar with this kind of creation. typeName<this,that,theOther> objName; What's with these <> brackets? How are they different than the old ( ) brackets? I never learned templates. My previous driver I was able to create it as a pointer and use newObj = new typeName(Params); Is there some sort of mapping between the two types or creators?
Thanks Millions!
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN3, RX_SIZE_256, TX_SIZE_16> Can0;
// CHANGED CAN0 to CAN3
void setup(void) {
Serial.begin(115200); delay(400);
pinMode(6, OUTPUT); digitalWrite(6, LOW); /* optional tranceiver enable pin */
Can0.begin();
Can0.setBaudRate(1000000);
Can0.setMaxMB(16);
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 > 200 ) {
CAN_message_t msg;
msg.id = random(0x1,0x7FE);
for ( uint8_t i = 0; i < 8; i++ ) msg.buf[i] = i + 1;
Serial.println("writing");
Can0.write(msg);
Can0.mailboxStatus();
timeout = millis();
}
}
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_INACTIVE
MB12 code: TX_INACTIVE
MB13 code: TX_INACTIVE
MB14 code: TX_INACTIVE
MB15 code: TX_INACTIVE