Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Teensy 3.6, Flexcan lib, dual canbus

  1. #1
    Junior Member
    Join Date
    Aug 2017
    Location
    Murfreesboro, Tn, USA
    Posts
    8

    Teensy 3.6, Flexcan lib, dual canbus

    Greetings All! I'm working on a project of applying a standalone Engine Control and utilizing a Teensy for the OEM integration of Canbus information and am currently backtracking to understand either where I lack subject knowledge,

    The aftermarket ecu has a limit up to 6 arbitration ID's sent and received, and 99 packets per Arbitration ID utilizing 7 bytes for actual data, with most parameters being user definable of variable start point, length, endian. Polling frequency can be ran at up to 200hz tx, no communicated limit on receiving data. The OEM ecu transmits 8 arbitration ID's and includes some parity bits, checksums, multipacket streams, etc. None of this really matters at this point and time, just an explanation of the big goal in hopes that I get led the right way towards it.

    Since I lack a solid background in C++, I know i'm gonna have to take this 1 step at a time, I set up my hardware to a proper canbus bus topology utilizing 120ohm termination resistors, and tried to run the examples in the flexcan library, as well as the github library with no luck (tried them all minus the object oriented extended id's, as i'm only running standard id's. only the object oriented sent "something" as my car responded in a spastic manner, but nothing was showing on the bus network out of the norm, and also modified all of the example sketches to 500k as that's the vehicle's bus speed ) . I expect to be missing something in the code, just clueless as to where.

    Platform is Windows10, Arduino IDE, with the Flexcan Library from Collin80 on Github. https://github.com/collin80/FlexCAN_Library

    Code:
    #include <FlexCAN.h>
    #include <kinetis_flexcan.h>
    
    // -------------------------------------------------------------
    // CANtest for Teensy 3.6 dual CAN bus
    // by Pawelsky (based on CANtest by teachop)
    //
    // This test transmits all data coming from CAN0 to CAN1 and vice versa (at 1Mbps)
    //
    
    #include <FlexCAN.h>
    
    #ifndef __MK66FX1M0__
      #error "Teensy 3.6 with dual CAN bus is required to run this example"
    #endif
    // modified file from 1m to 500kbps
    FlexCAN CANbus0(500000);
    FlexCAN CANbus1(500000);
    
    static CAN_message_t msg;
    static uint8_t hex[17] = "0123456789abcdef";
    
    
    // -------------------------------------------------------------
    static void hexDump(uint8_t dumpLen, uint8_t *bytePtr)
    {
      uint8_t working;
      while( dumpLen-- ) {
        working = *bytePtr++;
        Serial.write( hex[ working>>4 ] );
        Serial.write( hex[ working&15 ] );
      }
      Serial.write('\r');
      Serial.write('\n');
    }
    
    
    // -------------------------------------------------------------
    void setup(void)
    {
      CANbus0.begin();
      CANbus1.begin();
      // added code from line 41 to 46 ----------------------------
      pinMode(28, OUTPUT);
      pinMode(35, OUTPUT);
    
      digitalWrite(28, LOW);
      digitalWrite(35, LOW);
      // added code from line 41 to 46 ---------------------------- 
      delay(5);
      Serial.println(F("Hello Teensy 3.6 dual CAN Test."));
    }
    
    
    // -------------------------------------------------------------
    void loop(void)
    {
      if(CANbus0.available()) 
      {
        CANbus0.read(msg);
    //    Serial.print("CAN bus 0: "); hexDump(8, msg.buf);
        CANbus1.write(msg);
      }
    
      if(CANbus1.available()) 
      {
        CANbus1.read(msg);
    //    Serial.print("CAN bus 1: "); hexDump(8, msg.buf);
        CANbus0.write(msg);
      }
    }
    All help is appreciated and thank you in advance.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Teensy 3.6 dual transceiver.jpg 
Views:	250 
Size:	46.0 KB 
ID:	12074  

  2. #2
    Junior Member
    Join Date
    Jan 2017
    Posts
    17
    Hello,

    most of my CAN work uses Teensy 3.2, so I had to set up a Teensy 3.6 with two transceicers first to check the example. But I can say the "CANTest" example included with Teensyduino 1.40 does work for me.

    The library included in Teensyduino is an older version of the Collin80 library. I'm still not sure if this is intentionally an old version, or simply a "don't care". But as far as I know, both versions work for basic applications. The newer one (and the nmea2000 fork) have some advantages in some applications.

    So if the example doesn't work for you, I would say you have a hardware problem.

    If the example works and you want to connect another CAN bus: This will only work if you use the baudrate of this other bus. I can't see any reason why you should use both bus interfaces of the Teensy in this case, except for testing. And you may have to remove your resistors from your setup, if you connect an other bus, that is already terminated.

  3. #3
    Junior Member
    Join Date
    Aug 2017
    Location
    Murfreesboro, Tn, USA
    Posts
    8
    While it's possible I have a hardware problem, im almost certain that isn't the case. Network layer is properly terminated and such, no additional terminations or anything. As for transceivers working, I'd expect them to be functioning as they're doing 'something' on the object oriented example as im getting error responses from the vehicle. Id certainly have to scope them to verify. I'll check the "Cantest" and see what differences I find.

  4. #4
    Senior Member
    Join Date
    Jun 2014
    Posts
    245
    Hi! Just got your email.
    You may want to try https://github.com/pawelsky/FlexCAN_Library which allows you to choose which CAN port you want to use.
    This should be the FlexCAN library fork that is included with Teensyduino, but I'm not 100% sure, although the on in Teensy Examples also allows more ports.
    Also don't forget that you need to connect CAN board ground (common GND) to the car's ground for correct transmission.

    Cheers,
    Paul

  5. #5
    Junior Member
    Join Date
    Aug 2017
    Location
    Murfreesboro, Tn, USA
    Posts
    8
    That may be the reason, as I left common ground unterminated. Ill terminate it to common ground and post my results no later than Monday! Thanks Paul!

  6. #6
    Senior Member
    Join Date
    Jun 2014
    Posts
    245
    Glad to help

Posting Permissions

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