Teensy 4.1 with CANBUS adapter and flexcan t4 - no CAN data stream?

Taymar

Member
Hi all,

I've got a teensy 4.1 board and a dual canbus transceiver from tindie (https://www.tindie.com/products/fusion/dual-can-bus-adapter-for-teensy-40-41/)

For starters, I want to read the canbus stream from a vehicle through the obd2 port. I've got the necessary cables and adapter, and them hooked up as follows:

teensy CAN board can1 high = pin6 on OBD2 connector (CAN high)
teensy CAN board can1 low = pin 14 on OBD2 connector (CAN low)
teensy CAN board can1 ground = pin 5 on OBD2 connector (signal ground)

I've tried the base example that comes with flexcan_t4 included with teensyduino, code pasted below.

The can.read() functions don't seem to be firing, and I'm seeing no output.

Eventually I need to sniff and filter can messages from the vehicle to display on a display. For now I would just love to be able to get ANY sign that the teensy can 'see' data on the vehicle's canbus.

I'm pretty new to this, so any pointers on next steps to troubleshoot would be very much appreciated. Thank you



Code:
#include <FlexCAN_T4.h>

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

void setup(void) {
  can1.begin();
  can1.setBaudRate(250000);
  can2.begin();
  can2.setBaudRate(250000);
}

void loop() {
  

  if ( can1.read(msg) ) {
    Serial.print("CAN1 "); 
    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[i]); Serial.print(" ");
    }
    Serial.print("  TS: "); Serial.println(msg.timestamp);
  }
  else 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[i]); Serial.print(" ");
    }
    Serial.print("  TS: "); Serial.println(msg.timestamp);
  }
}
 
When I first started tinkering with the Teensy 4.x CAN capabilities, I found a recommendation by PaulS (see <this> post elsewhere) for an inexpensive CAN analyzer that proved to be an immense help in troubleshooting my early attempts with reading the CAN data from the OBDII port on my Honda Civic. That particular analyzer is also capable of sending data, so you can check your ability to receive from a known-good source that way.

As an alternate quick test, you are welcome to try my sketch as given in <this> post to see if it is able to see any data from your OBDII port.

Something (else) to double-check: how confident are you that your OBDII port data is at 250kbaud ??

Good luck !!

Mark J Culross
KD5RXT
 
Thank you Mark! I will get one of those CAN analyzers. Will also see if I can get your sketch to work with my setup - thank you.

That's a great question on the port data speed, as of now, not very confident. From the info I've been able to piece together, I believe the vehicle uses two separate can networks, high and low speed. The high speed is (I think) 500kb/s. I have not been able to find a spec for the low speed.

Is changing this as simple as setting

can1.setBaudRate(250000);

to

can1.setBaudRate(500000);


or is there more to it than that?

Thank you again for the help and advice!
 
Thank you Mark! I will get one of those CAN analyzers. Will also see if I can get your sketch to work with my setup - thank you.

That's a great question on the port data speed, as of now, not very confident. From the info I've been able to piece together, I believe the vehicle uses two separate can networks, high and low speed. The high speed is (I think) 500kb/s. I have not been able to find a spec for the low speed.

Is changing this as simple as setting

can1.setBaudRate(250000);

to

can1.setBaudRate(500000);


or is there more to it than that?

Thank you again for the help and advice!

@Taymar:

Yes, you should be able to test at different rates with the changes as you have shown. Good luck & feel free to ask any other questions that may come up.

Mark J Culross
KD5RXT

P.S. One of the capabilities that I put into my sketch was to "hunt" for the baud rate in use by scanning thru the different rates and/or to manually step thru the different rates (since I, likewise, was not 100% sure of the rate needed for my Honda Civic), so hopefully, if you aren't able to make a positive rate determination otherwise, this might help. MJC
 
Thanks guys! I did not manage to get anything using my original sketch updated to 500. Will report back on how it goes.

I did just measure between the can H and can L pins on my adapter (where it connects to the OBD2 cable). I got a 120 ohm reading so I'd presume that means my adapter already has the necessary resistor? or am I misunderstanding that piece?

I have my CAN board connected to a 9 pin D sub/serial connector, which then connects into the OBD2 cable.

Thank you again, really appreciate the help!
 
It does not hurt to swap the H & L lines as PaulS is recommending.

On the 120 Ohm issue, the resistor needs to reside on both sides per the link I sent before .... In my case, the circuit was working at lower speeds until I raised the speed to 500 Kb where it stopped working. The 120 Ohm resistor between the Can lines fixed the problem ...

BTW, I did not use the Tindie CAN attachment. The most reliable CAN product I found is this one here. Granted, it is not as slick as Tindie's ...

https://www.amazon.com/SN65HVD230-CAN-Board-Communication-Development/dp/B00KM6XMXO/
 
I have my CAN board connected to a 9 pin D sub/serial connector
Did you connect it according to this pinout? (no need to connect VCC)

OBD2DB9.PNG

Paul
 
The OBDII port I've seen uses 500k. Suggest you tried that.

Depend on the make/model/year of your vehicle you may not see any data on its own. The OBDII port is not usually directly connected to the CAN network.
It is via a gateway. You would need to do a request first, then the gateway will respond.

Try a sending a coolant temperature request:

ID:7DF Data:02 01 05 00 00 00 00 00

You should then see a reply.

Make sure you turn your ignition key switch to run.
 
Thanks again all. To answer the questions:

Please see attached screenshot on how I've got it wired, with the pins etc.

@jimmie - where in this would I need to attach the resistor please? would it be between pins 3 and 5 on the RS232 male plug?

I'll try swapping the CAN lines and see if that helps.

@PaulS - My DB9 pins are different to the table you posted (I had to use the premade cable). On the OBD connector, mine shows pin 4 is vehicle ground and pin5 is signal ground. I'm using 5 instead of 4. Should I try and switch that?

@skpang - Thank you, that would make sense. Right now I'm testing on a 2012 chrysler/dodge. Once I've proved the concept works, it will be connected to a Haltech standalone ECU which has direct CAN access. I will see if I can figure out how to send a request in the code.

Greatly appreciate it all, thank you so much! Will do some more testing and report back.


Screenshot 2023-04-24 094156.jpg
 
@Taymar

I am not using an RS232 plug but the resistor needs to be between the Can H and Can L lines on the Teensy side.

In my installation, I am using a Waveshare Can module connected to my Teensy. So the resistor is between the Can H & L lines of the Waveshare module.
 
The bus needs 2 x 120ohm termination resistors. You should measure 60ohms when fully connected & powered down.

Fully connected to the vehicle? I measure 120 ohms between the high and low wires at my RS232 plug, without the OBD section connected.

I measure 32 MegaOhms between either can wire and GROUND.
 
When fully connected to the vehicle you should see 60Ω. Your measurement of 120Ω is correct for a not-connected OBD plug.

Paul
 
When fully connected to the vehicle you should see 60Ω. Your measurement of 120Ω is correct for a not-connected OBD plug.

Paul

Thanks Paul, I checked - vehicle connected, no USB power to Teensy. I measure 40.5 ohms. No different with vehicle ignition on vs. vehicle ignition off. So do I just need to add a 120 ohm resistor into the cable as pictured in the attachment?

Or does my 40.5 ohm reading suggest something else is wrong?

thanks so much for all the help.

Screenshot 2023-04-25 105532.jpg
 
dont add terminations in a vehicle, the vehicle is already terminated.

if devices you have added have resistors, remove their resistors.

if your cluster goes limp, your CANL & CANH lines are reversed. fix them and after a few drives the errors should clear.
 
Thank you, please excuse yet more ignorance from my side - the CAN device has some traces you can cut to change the configuration. It looks to me like these are more for setting read/write/read only mode etc, but also sounds like they pull certain pins to ground. Would cutting one of these traces have the same effect as removing the resistor or are they completely different things? I don't know that I have the tools to replace the resistor later if needed so want to be sure before I cut it off the board.

thank you

https://www.tindie.com/products/fusion/dual-can-bus-adapter-for-teensy-40-41/

2021-04-18T20_39_23.000Z-5@1500x-100.jpg
 
Would cutting one of these traces have the same effect as removing the resistor or are they completely different things?
Cutting the traces does not have the same effect as removing the resistors. It's for setting the CAN chip in a certain mode.
So you have to remove that resistor carefully from the PCB.

Paul
 
Thank you Paul - My USB CAN analyzer just showed up, going to see if I can get anything to read through that first then will report back.

Much appreciated.
 
Last edited:
there should be 2x 120 ohm on that PCB
```This tiny Teensy add-on board features dual CAN-Bus transceiver circuits, including termination resistors```
1x 120 ohm per bus, most likely the ones on the side, i tried to find the datasheet but they didn't list it, you could measure the resistor and each side of it's pad should trace directly to the CANH/CANL pin
 
Well after a bit of trial and error I THINK I have had some success with the USB can debugger.


I set it to 500Kbps, and sent the request for coolant temp as @skpang mentioned: ID:7DF Data:02 01 05 00 00 00 00 00

I got back a response as shown in the screenshot. I couldn't get the left click hex to dec to work, but I do see the 4th set of hex digits did slowly increment as the engine was running. Not quite sure how to decipher these yet.

So based on what you've all told me here - fair to say my vehicle is using a gateway that won't just expose all the CAN stream, I have to ask it for a piece of data and it responds?

Would there be any issue on the vehicle side if I'm polling it rapidly? i.e. my requests won't slow down the vehicle can bus or something like that.

Thank you again for all the help, this is a baby step but really exciting!

View attachment 31034
 
you wont slow them down unless you're flooding the bus, even at 50ms gaps you should be fine, but recommend you be lenient
 
there should be 2x 120 ohm on that PCB
```This tiny Teensy add-on board features dual CAN-Bus transceiver circuits, including termination resistors```
1x 120 ohm per bus, most likely the ones on the side, i tried to find the datasheet but they didn't list it, you could measure the resistor and each side of it's pad should trace directly to the CANH/CANL pin

Thank you!

Would the need for a termination resistor change if I'm tapped directly into the CAN lines vs. going through the OBD port?

Reason I ask, is for now I'm testing on a Dodge vehicle via OBD2. For the real application, it'll be connected to the CAN on a standalone ECU made by Haltech. I guess I can get another can board honestly they're relatively inexpensive. Just wondered if removing the resistor for my tests would need me to add it back in for the 'real' application.

thank you again ever so much
 
Back
Top