Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 28

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

  1. #1
    Junior Member
    Join Date
    Apr 2023
    Posts
    10

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

    Hi all,

    I've got a teensy 4.1 board and a dual canbus transceiver from tindie (https://www.tindie.com/products/fusi...-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);
      }
    }

  2. #2
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    659
    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

  3. #3
    Junior Member
    Join Date
    Apr 2023
    Posts
    10
    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!

  4. #4
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    659
    Quote Originally Posted by Taymar View Post
    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

  5. #5
    Senior Member
    Join Date
    Jun 2017
    Posts
    250
    I had a similar issue.

    The library can work at speeds of 1000 Kb but I am using 500 Kb.

    The reason you may not be getting an output from the bus was resolved in my case my adding a 120 Ohm resistor across the Can H and L lines. Most Can interfaces will have the resistor on the sensor side but you need one on the board side.

    This link may be helpful: https://support.enovationcontrols.co...de-with-Video-

  6. #6
    Junior Member
    Join Date
    Apr 2023
    Posts
    10
    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!

  7. #7
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    1,248
    Did you try swapping the CAN-L and CAN-H lines? (been there, done that...)

    Paul

  8. #8
    Senior Member
    Join Date
    Jun 2017
    Posts
    250
    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-CA...dp/B00KM6XMXO/

  9. #9
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    1,248
    Quote Originally Posted by Taymar View Post
    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)

    Click image for larger version. 

Name:	OBD2DB9.PNG 
Views:	15 
Size:	8.3 KB 
ID:	30980

    Paul

  10. #10
    Senior Member skpang's Avatar
    Join Date
    Jan 2015
    Location
    UK
    Posts
    242
    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.

  11. #11
    Junior Member
    Join Date
    Apr 2023
    Posts
    10
    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.


    Click image for larger version. 

Name:	Screenshot 2023-04-24 094156.jpg 
Views:	26 
Size:	35.0 KB 
ID:	30994

  12. #12
    Senior Member
    Join Date
    Jun 2017
    Posts
    250
    @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.

  13. #13
    Senior Member
    Join Date
    Feb 2020
    Posts
    144
    The bus needs 2 x 120ohm termination resistors. You should measure 60ohms when fully connected & powered down.

  14. #14
    Junior Member
    Join Date
    Apr 2023
    Posts
    10
    Quote Originally Posted by TeensyWolf View Post
    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.

  15. #15
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    1,248
    When fully connected to the vehicle you should see 60Ω. Your measurement of 120Ω is correct for a not-connected OBD plug.

    Paul

  16. #16
    Junior Member
    Join Date
    Apr 2023
    Posts
    10
    Quote Originally Posted by PaulS View Post
    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.

    Click image for larger version. 

Name:	Screenshot 2023-04-25 105532.jpg 
Views:	24 
Size:	35.6 KB 
ID:	31013

  17. #17
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    4,095
    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.

  18. #18
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    1,248
    Quote Originally Posted by Taymar View Post
    Or does my 40.5 ohm reading suggest something else is wrong?Click image for larger version. 

Name:	Screenshot 2023-04-25 105532.jpg 
Views:	24 
Size:	35.6 KB 
ID:	31013
    Three 120Ω resistors in parallel make ~40.5Ω. So like Tonton81 suggested, remove the 120Ω resistor from your CAN device.

    Paul

  19. #19
    Junior Member
    Join Date
    Apr 2023
    Posts
    10
    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/fusi...-teensy-40-41/

    Click image for larger version. 

Name:	2021-04-18T20_39_23.000Z-5@1500x-100.jpg 
Views:	14 
Size:	68.5 KB 
ID:	31023

  20. #20
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    1,248
    Quote Originally Posted by Taymar View Post
    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

  21. #21
    Junior Member
    Join Date
    Apr 2023
    Posts
    10
    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 by Taymar; 05-01-2023 at 01:03 AM.

  22. #22
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    4,095
    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

  23. #23
    Junior Member
    Join Date
    Apr 2023
    Posts
    10
    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!

    Attachment 31034

  24. #24
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    4,095
    you wont slow them down unless you're flooding the bus, even at 50ms gaps you should be fine, but recommend you be lenient

  25. #25
    Junior Member
    Join Date
    Apr 2023
    Posts
    10
    Quote Originally Posted by tonton81 View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •