Teensy 4.1 and CAN (with FlexCAN_T4)

Status
Not open for further replies.

juanperez

Member
Good morning guys

I have been trying all morning to make a simple CAN communication but there is no way (I have read several threads about it in this forum)

I write this code:

#include <FlexCAN_T4.h>

FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> can2;
CAN_message_t msg;

void setup() {

Serial.begin(115200);

can2.begin();
can2.setBaudRate(250000);

}

void loop() {

msg.id = 0x100;
msg.len = 8;
msg.flags.extended = 0;
msg.flags.remote = 0;
msg.flags.overrun = 0;
msg.flags.reserved = 0;
msg.buf[0] = 10;
msg.buf[1] = 20;
msg.buf[2] = 0;
msg.buf[3] = 100;
msg.buf[4] = 128;
msg.buf[5] = 64;
msg.buf[6] = 32;
msg.buf[7] = 16;

can2.write(msg);

if ( can2.read(msg) ) {
Serial.print("CAN2 ");
Serial.print("MB: "); Serial.print(msg.mb);
Serial.print(" ID: 0x"); Serial.print(msg.id, HEX );
Serial.print(" EXT: "); Serial.print(msg.flags.extended );
Serial.print(" LEN: "); Serial.print(msg.len);
Serial.print(" DATA: ");
for ( uint8_t i = 0; i < 8; i++ ) {
Serial.print(msg.buf); Serial.print(" ");
}

}

}



But no send / receive anything. Use a TJA1051T transceiver. Also use a USB/CAN adaptor to check connection, but no receive any message and if send a message Teensy no receive it.


Any idea?
 
what pins are you using on teensy? CAN2 uses pins 0 and 1, also confirm first with the fifo interrupt example, it works as is just change the bus to CAN2 in constructor, if that still doesn't work, try to print mailboxStatus() from the loop(), if the transmit mailboxes keep filling up, and not clearing, that means you have a bad connection issue and it's not software end (unless baudrate is wrong)

Also not a good idea to flood the bus, you're constantly flooding transmits in an endless loop
 
Yes, use pins 0 and 1. 0 (rx) to Tx on transceiver, and 1 (tx) to Rx on transceiver.

fifo example not work, but if print mailboxStatus() show:

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)
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)
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)
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)
.
.
.


Transceiver is powered by 5V, like as datasheet.
 
check your transceiver's operating mode as well as per datasheet. 2 pins are involved. EN should be tied HIGH and S should be tied LOW

Screenshot_20210302-083534_Drive.jpg

also you should be using the /3 chip model for Teensy, not the /E

Screenshot_20210302-085616_Drive.jpg

The TJA1051 is available in three versions, distinguished only by the function of pin 5: • The TJA1051T is backwards compatible with the TJA1050 • The TJA1051T/3 and TJA1051TK/3 allow for direct interfacing to microcontrollers with supply voltages down to 3 V • The TJA1051T/E allows the transceiver to be switched to a very low-current Off mode.
 
Last edited:
Thank for your reply.

Use TJA1051T/2Z, i will try TJA1051T/3. I will post a new answer when I test with this model.

Thanks!
 
Hi guys,
I am testing with the TJA1051T/3 version (which should work at 3.3v) but I am not getting any satisfactory results.

The connections are as follows:
1 - TXD - to pin 1 Teensy
2 - GND
3 - 5V
4 - RXD - to pin 0 Teensy
5 - NC
6 - CAN-L
7 - CAN-H
8 - GND

Beetween CAN-L and CAN-H connect a 120ohm resistor, also in can-usb adaptor. Total impedance on bus are 60ohm.

Any idea?

Regards
 
read the blue
Screenshot_20210309-022559_Adobe Acrobat.jpg

The TJA1051T/3 and TJA1051TK/3 allow for direct interfacing to microcontrollers with supply voltages down to 3 V

7.2.2 Internal biasing of TXD, S and EN input pins Pin TXD has an internal pull-up to VIO and pins S and EN (TJA1051T/E) have internal pull-downs to GND. This ensures a safe, defined state in case one or more of these pins is left floating.

7.3 VIO supply pin There are three versions of the TJA1051 available, only differing in the function of a single pin. Pin 5 is either an enable control input (EN), a VIO supply pin or is not connected. Pin VIO on the TJA1051T/3 and TJA1051TK/3 should be connected to the microcontroller supply voltage (see Figure 6 ). This will adjust the signal levels of pins TXD, RXD and S to the I/O levels of the microcontroller. For versions of the TJA1051 without a VIO pin, the VIO input is internally connected to VCC. This sets the signal levels of pins TXD, RXD and S to levels compatible with 5 V microcontrollers.


So, with 7.3 section, you must supply 3.3v to Vio pin 5
 
Status
Not open for further replies.
Back
Top