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

Thread: Cant get CAN to work on Teensy 3.6 with the dual can board

  1. #1
    Junior Member
    Join Date
    Jun 2019
    Posts
    13

    Cant get CAN to work on Teensy 3.6 with the dual can board

    I cant get any data from my system to the teensy. I currently have the CAN hooked up to my system (white HIGH, Blue Low, Orange is ground)

    I am using CAN 1 on the dual CAN board. any reason why I'm not seeing anything?


    the message i am sending over is ID 0x265 16bit long start bit 0, Little Endian (Intel) and its just a constant 12.345 to see if anything works.

    Any ideas as to why this isn't working?




    Code:
    #include <IFCT.h>
    
    void setup() {
      pinMode(2, OUTPUT); // for the transceiver enable pin
      Can1.setBaudRate(1000000);
      Can1.enableFIFO();
    }
    
    void loop() {
      CAN_message_t msg;
      if ( Can1.read(msg) ) canSniff(msg);
    }
    
    void canSniff(const CAN_message_t &msg) {
      Serial.print("MB "); Serial.print(msg.mb);
      Serial.print("  LEN: "); Serial.print(msg.len);
      Serial.print(" EXT: "); Serial.print(msg.flags.extended);
      Serial.print(" REMOTE: "); Serial.print(msg.rtr);
      Serial.print(" TS: "); Serial.print(msg.timestamp);
      Serial.print(" ID: "); Serial.print(msg.id, HEX);
      Serial.print(" Buffer: ");
      for ( uint8_t i = 0; i < msg.len; i++ ) {
        Serial.print(msg.buf[i], HEX); Serial.print(" ");
      } Serial.println();
    }

  2. #2
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,196
    Not sure what you have it attached to, but make sure on the other end you have low to low, high to high to high, gnd to gnd. Also make sure your baud rates match.

  3. #3
    Junior Member
    Join Date
    Jun 2019
    Posts
    13
    Its attached to a data logging system. All wires are connected correctly on the data system.

    I changed it to CAN0 but still get nothing. I know things are on that CAN bus so its strange I get nothing.

    Only thing I can think of is that I am using CAN 1 alt and dont know how to modify the code to make it use that one. Also with the tindy dual can bus pcb how do i pull the Rs* pin down so it stays in high powered mode?

    Any help would be great.

  4. #4
    Have you got a 120R terminator on both end ?

  5. #5
    Junior Member
    Join Date
    Jun 2019
    Posts
    13
    Yea, the resistor is turned on in the data system and then there is a 120 ohm resistor on the fusion pcb. I tried to turn off the data systems resistor and still nothing.

    Im wondering if there is something to do with the transever. pin 2 isnt attached to anything and i dont know if i need to make that another pin that goes to the receiver.

  6. #6
    Use a scope and check the signals.

    You should see data on CAN_L and CAN_H.

    On the Teensy side you should see data on the CAN Rx pin.

  7. #7
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,112
    there are 3 pins per chip side on teensy, 2 are for can lines, the other 1 is the transceiver enable pin. enable the pin and digitalwrite it ground

  8. #8
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,196
    Instead of doing pinmod(2, OUTPUT); digitalWrite(2, LOW) you will probably need to do a:
    Code:
     pinMode(35, OUTPUT); // for the transceiver enable pin
    digitalWrite(35, LOW);
    Looks like 2 problems you have to fix (1) use the correct enable pin and (2) then pull it low. Since you have it soldered on the T3.6 have to use 35 for CAN1 and 28 for CAN0. Schematic with the pinouts is here: https://www.tindie.com/products/Fusi...-teensy-35-36/

  9. #9
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,112
    Also tell the library to use the alt pins for Can0, which is normally 3 and 4 for default, you need to change them

  10. #10
    Junior Member
    Join Date
    Jun 2019
    Posts
    13
    Quote Originally Posted by tonton81 View Post
    Also tell the library to use the alt pins for Can0, which is normally 3 and 4 for default, you need to change them
    I am looking at the IFCT Library and I am unsure of where to actually change whats been declared. I dont see anything in the IFCT.h that mentions the pin and there is some in the IFCT.cpp that mentions CORE_PIN3,29,30,33,34 but dont know what to change there as they seem to all be on if tx ==3 then tx==29 so it should fall over right?

    Quote Originally Posted by mjs513 View Post
    Instead of doing pinmod(2, OUTPUT); digitalWrite(2, LOW) you will probably need to do a:

    Code:
     pinMode(35, OUTPUT); // for the transceiver enable pin
    digitalWrite(35, LOW);
    Looks like 2 problems you have to fix (1) use the correct enable pin and (2) then pull it low. Since you have it soldered on the T3.6 have to use 35 for CAN1 and 28 for CAN0. Schematic with the pinouts is here: https://www.tindie.com/products/Fusi...-teensy-35-36/
    THanks, I will try that. I have switched back to CAN0 to try it but CAN1 may be a tad easier since I wont have to mod any of the library.



    Thanks, guys I appreciate the help

  11. #11
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,196
    @slythy

    Try that enabling pin 35 like I recommended before changing to CAN0.

    EDIT: its been awhile since I used IFCT but just checked:
    Code:
    CAN0.setTX(ALT);
    CAN0.setRX(ALT);
    I think is all that is need to use the alt pins for CAN0

    Recommend looking at the Readme for the IFCT library and the datasheet for the dual can board you have. It helps in understanding the hook ups and what is available.
    Last edited by mjs513; 09-11-2019 at 08:36 PM.

  12. #12
    Junior Member
    Join Date
    Jun 2019
    Posts
    13
    Here is my code as it sits, My Serial monitor is still blank. I get 120ohms across the lines when i beep them out. I have a decent amount coming across that bus right now so I cant believe its not seeing anything.

    is there a 0x0XX-0x999 range limit or something?


    Code:
    #include <IFCT.h>
    
    void setup() {
    
    pinMode(28, OUTPUT); // for the transceiver enable pin
    digitalWrite(28,LOW);
      
    Can0.setTX(ALT);
    Can0.setRX(ALT);
    Can0.setBaudRate(1000000);
    Can0.enableFIFO();
    
    }
    
    void loop() {
      CAN_message_t msg;
      if ( Can0.read(msg) ) canSniff(msg);
      
    }
    
    void canSniff(const CAN_message_t &msg) {
      Serial.print("MB "); Serial.print(msg.mb);
      Serial.print("  LEN: "); Serial.print(msg.len);
      Serial.print(" EXT: "); Serial.print(msg.flags.extended);
      Serial.print(" REMOTE: "); Serial.print(msg.rtr);
      Serial.print(" TS: "); Serial.print(msg.timestamp);
      Serial.print(" ID: "); Serial.print(msg.id, HEX);
      Serial.print(" Buffer: ");
      for ( uint8_t i = 0; i < msg.len; i++ ) {
        Serial.print(msg.buf[i], HEX); Serial.print(" ");
      } Serial.println();
    }

  13. #13
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,196
    Sounds like at this point you have a baud rate mismatch. Whats the baud rate coming from the data system? They have to match. Are you using CAN 2.0 or CAN-FD on your data side? Assuming its CAN 2.0. Is there a transceiver on the data side?

  14. #14
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,196
    Also did you try the example that is provided with the library for a sniffer?

  15. #15
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,112
    your sketch looks alright, check the baudrate is correct and dont cross the canh/canl lines, must be canh to canh, canl to canl, and common ground, either from teensy or the ground pin of the shield

  16. #16
    Junior Member
    Join Date
    Jun 2019
    Posts
    13
    Ok progress! I have 8 CAN busses on my data system and I read the data sheet wrong. Now i get some messages. Is the buffer the start of each of the 8 messages? I notice when I shift it around that C moves.

    So my data getting sent over is 16bit long message. the entire packet is 64 bits. How do I actually see the data that is read? I need to be able to save what it reads as a value. So that 12.345 will be a sensor sent over CAN and I need to do math on that to direct the outputs. Im going to have like 10 sensor inputs (which is why I'm trying CAN over analog in).

    Any idea?


  17. #17
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,112
    yes buffer is the data field output, 8 bytes, you can access the bytes from the canSniff function

    16 bits is 2 data bytes

    (uint16_t)(msg.data[0] << 8) | msg.data[1];
    should join 2 bytes to get the 16 bit result you want
    Last edited by tonton81; 09-12-2019 at 04:20 PM.

Posting Permissions

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