I’m trying to send CAN messages with a Teensy 4.0 & a CAN tranceiver CJMCU-2551.
I’ve connected as follow:
- Teensy Pin 23 (TX1) → CJMCU-2551 TXD.
- Teensy Pin 22 (RX1) → CJMCU-2551 RXD.
- Teensy GND → CJMCU-2551 GND.
- Teensy 3.3V (VCC) → CJMCU-2551 VCC. (EDIT: This was the mistake. It’s hold be 5volt)
- CJMCU-2551 CANH → CAN bus CANH on a VN1610
- CJMCU-2551 CANL → CAN bus CANL on a VN1610
#include <FlexCAN_T4.h> // Include the FlexCAN_T4 library for Teensy 4.0
// Define CAN bus object using CAN1
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> CanBus;
// Define message parameters
const int ledPin = 13; // Define LED pin for activity indicator
const uint32_t baudRate = 500000; // CAN baud rate (500 kbps)
const uint32_t sendInterval = 500; // Interval to send messages (milliseconds)
CAN_message_t msg; // Define CAN message object
void setup() {
// Initialize serial communication for debugging
Serial.begin(115200);
// Initialize LED pin
pinMode(ledPin, OUTPUT);
// Initialize CAN bus at 500 kbps
CanBus.begin();
CanBus.setBaudRate(baudRate);
// Prepare CAN message
msg.id = 0x123; // Standard CAN ID
msg.len = 8; // Data length (8 bytes)
msg.flags.extended = 0; // Standard frame (11-bit identifier)
msg.buf[0] = 0x11; // Example data
msg.buf[1] = 0x22;
msg.buf[2] = 0x33;
msg.buf[3] = 0x44;
msg.buf[4] = 0x55;
msg.buf[5] = 0x66;
msg.buf[6] = 0x77;
msg.buf[7] = 0x88;
Serial.println("CAN bus initialized at 500 kbps.");
}
void loop() {
// Send the CAN message
CanBus.write(msg);
// Print the message to Serial Monitor
Serial.print("Sent CAN message ID: 0x");
Serial.print(msg.id, HEX);
Serial.print(" Data: ");
for (int i = 0; i < msg.len; i++) {
Serial.print(msg.buf[i], HEX);
Serial.print(" ");
}
Serial.println();
// Blink the LED to indicate activity
digitalWrite(ledPin, HIGH);
delay(100); // LED on for 100 ms
digitalWrite(ledPin, LOW);
delay(sendInterval - 100); // Adjust delay to maintain 500 ms interval
}
The code does not through any fault but still I cant observer any message in CANalyzer.
Here is how my settings looks like in CANalyzer.
according to above
1