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

Thread: Teensy 3.6 CAN-RTR message

  1. #1
    Junior Member
    Join Date
    Jan 2019
    Posts
    6

    Teensy 3.6 CAN-RTR message

    Hi,
    I need to send a RTR message from the a teensy 3.6. But when i do, the microcontroller stops sending CAN-messges after the second RTR-message is sent.
    So the Teensy sends 2 RTR-messages, I receive the data, but then i stops sending CAN-data even though the microcontroller still runs and prints data to the serial port.

    This is how i setup the CAN:

    void setup()
    {
    CAN_filter_t myFilter;
    myFilter.rtr = 0;
    myFilter.id = 0;
    myFilter.ext = 0;

    Can0.begin(500000,myFilter,1,1);
    Can1.begin(500000,myFilter,1,1);

    Can0.attachObj(&odrv1); // make child of can class to receive new messages automatically
    Can1.attachObj(&macs1); // make child of can class to receive new messages automatically
    ...
    }

  2. #2
    Junior Member
    Join Date
    Jan 2019
    Posts
    6
    Aslo, I am using the FlexCAN-library (#include <FlexCAN.h>), and a dual can-transceiver from tindie: https://www.tindie.com/products/Fusi...-teensy-35-36/

  3. #3
    Junior Member
    Join Date
    Jan 2019
    Posts
    6
    I have tried different versions of the FlexCAN library, current version is "Collin80"' version, but still no luck. I see the same behaviour from all of the libraries; I am able to send 2 RTR-messages.
    Anyone who know how to debug this? I'm completely lost...

    Code:
    /*
     * Object Oriented CAN example for Teensy 3.6 with Dual CAN buses 
     * By Collin Kidder. Based upon the work of Pawelsky and Teachop
     * 
     * Both buses are set to 500k to show things with a faster bus.
     * The reception of frames in this example is done via callbacks
     * to an object rather than polling. Frames are delivered as they come in.
     */
    
    #include <FlexCAN.h>
    
    #ifndef __MK66FX1M0__
      #error "Teensy 3.6 with dual CAN bus is required to run this example"
    #endif
    
    static CAN_message_t msg;
    static uint8_t hex[17] = "0123456789abcdef";
    
    class ExampleClass : public CANListener 
    {
    public:
       void printFrame(CAN_message_t &frame, int mailbox);
       bool frameHandler(CAN_message_t &frame, int mailbox, uint8_t controller); //overrides the parent version so we can actually do something
    };
    
    void ExampleClass::printFrame(CAN_message_t &frame, int mailbox)
    {
       Serial.print("ID: ");
       Serial.print(frame.id, HEX);
       Serial.print(" Data: ");
       for (int c = 0; c < frame.len; c++) 
       {
          Serial.print(frame.buf[c], HEX);
          Serial.write(' ');
       }
       Serial.write('\r');
       Serial.write('\n');
    }
    
    bool ExampleClass::frameHandler(CAN_message_t &frame, int mailbox, uint8_t controller)
    {
        printFrame(frame, mailbox);
    
        return true;
    }
    
    ExampleClass exampleClass;
    
    // -------------------------------------------------------------
    void setup(void)
    {
      delay(1000);
      Serial.println(F("Hello Teensy 3.6 dual CAN Test With Objects."));
    
      CAN_filter_t myFilter;
      
      Can0.begin(500000,myFilter,1,1);  // ODRV - TEENSY - ODRV
      Can1.begin(500000,myFilter,1,1);  // MACS - TEENSY - MACS
      
    
      //if using enable pins on a transceiver they need to be set on
      pinMode(28, OUTPUT);
      pinMode(35, OUTPUT);
    
      digitalWrite(28, LOW);
      digitalWrite(35, LOW);
    
      Can0.attachObj(&exampleClass);
      exampleClass.attachGeneralHandler();
    
      msg.ext = 0;
      msg.id = 0x100;
      msg.len = 8;
      msg.rtr = 1;
      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;
    }
    
    
    // -------------------------------------------------------------
    void loop(void)
    {
      msg.buf[0]++;
      Can1.write(msg);
      msg.buf[0]++;
      Can1.write(msg);
      msg.buf[0]++;
      Can1.write(msg);
      msg.buf[0]++;
      Can1.write(msg);
      msg.buf[0]++;
      Can1.write(msg);  
      delay(20);
    }

  4. #4
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,996
    when flexcan transmits an rtr frame the mailbox itself switches to reception mode to intercept the frame, if it never comes in, and your sending doesnt force it back on next write, it just wont do anything in that mode. I don’t believe the stock libraries were tested/configured for rtr messages. RTR messages are also close to extinction..

  5. #5
    Also RTR has been removed in the CAN FD spec.

  6. #6
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,996
    indeed, i believe it’s been used in FD to enable 12bit standard CAN ids, like in the MCP2517FD controller.

  7. #7
    Junior Member
    Join Date
    Jan 2019
    Posts
    6
    Thanks all,
    I did write a message back, but could not get it to work. Instead of RTR, I changed to sourcecode of the device requesting the RTR to use other CAN-messages.

Posting Permissions

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