Forum Rule: Always post complete source code & details to reproduce any issue!
Page 7 of 7 FirstFirst ... 5 6 7
Results 151 to 167 of 167

Thread: Another fork of FlexCAN

  1. #151
    I have a question regarding usage of the Rx mailboxes, and how they can be configured to best manage incoming messages.
    I have filters and masks set to receive important messages in particular mailboxes. Some messages I decode and process (first five mailboxes), some messages get passed to the other bus (next 3 mailboxes). However, all messages are logged to the SD card (remaining mailboxes). My problem is that I cannot guarantee that my important messages are processed by the correct mailbox handler as these messages can be accepted by the 'catch-all' mailboxes.
    I am guessing that I have to abandon filters and masks and handle all incoming messages with the General Handler, and filter my important messages in software.
    The Kinetis manual does mention:
    Selectable priority between mailboxes and Rx FIFO during matching process
    Powerful Rx FIFO ID filtering, capable of matching incoming IDs against either 128 extended, 256 standard, or 512 partial (8 bit) IDs, with up to 32 individual masking capability
    Is there anything I could do to make use of the mailboxes?
    I realize that I could close-down my 'catch-all' mailboxes to only receive messages outside of the 'important' message range but my application has the ability to read and write Filters to the SD, and also modify them during run-time, which would potentially make this approach quite complex.

    Any suggestions much appreciated.
    EDIT: It looks like configuring a pair of mailboxes for a particular message might be a solution, though this obviously reduces the number of available unique tasks to 7 ID's or ranges of ID's.
    Last edited by Darcy; 02-04-2018 at 09:06 PM.

  2. #152
    Junior Member
    Join Date
    Sep 2018
    Location
    san francisco
    Posts
    2
    hello guys i am very new to teensy and i and have teensy3.6 and i also bought two Single CAN-Bus adapter for Teensy from TinDie and i am trying to use two teensy3.6 and get them talk to each other just basic sending and receiving messages. please if there is any help to connect the hardware that will be awesome

  3. #153
    Junior Member
    Join Date
    Dec 2018
    Posts
    5
    Is 2M baud rate supported by FlexCAN library? Will it work on Teensy 3.6?

    -albertr

  4. #154
    Quote Originally Posted by albertr View Post
    Is 2M baud rate supported by FlexCAN library? Will it work on Teensy 3.6?

    -albertr
    No, Teensy 3.6 only has Classic CAN, which the max rate is 1mbps.

    If you want 2mbps then you need CAN FD.

  5. #155
    Junior Member
    Join Date
    Sep 2019
    Location
    UK
    Posts
    10
    Hi
    I'd really appreciate some help in setting up a mask and filters for a project I'm working on. I've read various posts and looked at example code but I'm getting lost on some of the terminology and options.

    I'm using a Teensy 3.2 to read four canbus messages from a marine engine. I want to only process data in messages with ID 0x280, 0x288, 0x380 and 0x588. I have tried to work out the required mask which I think should be 0xB88 but don't know what to do next. Some posts show setting up mailboxes with filters whereas others don't seem to at all. It's all 11bit standard ID.

    Once I get the hang of this I'll be using a Teensy 3.6 to get certain bytes of the can bus data from the engine and put it onto a different canbus for the navigation display (NMEA2000).

    Keith

  6. #156
    Junior Member
    Join Date
    Sep 2019
    Location
    UK
    Posts
    10
    Ok, since my previous post I've made some progress in understanding this all a bit more. One outstanding question though is how to set listen only mode. I just want to silently sniff the bus and extract data. My code will be polling the buffered data rather than using object oriented callbacks. Where and how do I set Listen Only?

  7. #157
    Junior Member
    Join Date
    Aug 2019
    Posts
    12
    From the flexcan.h header file:

    //new functionality added to header but not yet implemented. Fix me
    void setListenOnly (bool mode); //pass true to go into listen only mode, false to be in normal mode
    Looks like listen only is not yet implemented. I don't know about your specific implementation but you can probably get away with normal mode and just not write anything to the transmit buffers. As far as I know this won't be truly silent as it will send an acknowledgement packet, but it's the next best thing. I've implemented a sniffer/splitter with a Teensy 3.6 and haven't run in to any issues yet with not being able to set an explicit listen only mode.

    Edit: Just looked in the flexcan.cpp file and the function appears to be there. Try Can0.setListenOnly(true); - not sure if it's been tested or not.

  8. #158
    Junior Member
    Join Date
    Sep 2019
    Location
    UK
    Posts
    10
    Thank you Dave. I also saw the reference to it not being implemented but also saw the bit in the .cpp file.

    Any thoughts on where I should place the command? Before Can.begin or after? Or maybe in the global section.

  9. #159
    I use the hardware to go into listen only mode on a SN65HVD230 (or poss is the VD231 variant) amd just pull a pin low in software.

  10. #160
    Junior Member
    Join Date
    Sep 2019
    Location
    UK
    Posts
    10
    Thanks Darcy. From the data sheet that would work with HVD230 but not HVD231. Guess which one my breakout board uses!

  11. #161
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,070
    Code:
    FlexCAN::setListenOnly
    Looked at that function, that looks correct it should be in listen only mode once set. ACKs and transmit wont work but receptions will

  12. #162
    Junior Member
    Join Date
    Sep 2019
    Location
    UK
    Posts
    10
    Well I'm making some progress. I tried the Can0.setListenOnly but that just seemed to stop all reception too. Perhaps I had it in the wrong place in my code.

    Code:
    void setup(void)
    {
      delay(5000);
      Serial.println(F("Hello Teensy 3.6 dual CAN Test."));
    
      Can0.setListenOnly (true); //hopefully set listen only mode
      
      Can0.begin(500000); //set baud. 
      
    }
    However, once commented out I did start receiving data but not quite what was expected. I was trying to only poll for byte 1 in 0x288 but was also getting byte 1 of all other frames as well.

    Code:
    CAN bus 0: 288, 56
    380, 68
    480, 28
    280, 0
    362, 0
    588, 16
    488, 0
    CAN bus 0:288, 56
    380, 68
    480, 28
    280, 0
    362, 0
    588, 16
    488, 0
    CAN bus 0:288, 56
    etc.....
    Code:
    // -------------------------------------------------------------
    // Development sketch to read VW marine can bus and filter relevant data
    // using polling
    //
    // by Collin Kidder, Based on CANTest by Pawelsky (based on CANtest by teachop)
    //
    // This sketch uses interrupt driven Rx. Rx frames
    // are internally saved to a software buffer by the interrupt handler.
    //
    
    #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";
    
    /*might need int not uint8_t
    uint8_t coolant; //unsigned integer coolant temp
    uint16_t rpm; //unsigned integer rpm
    uint8_t boost; //unsigned integer boost pressure
    uint8_t iat; //unsigned integer intake air temp*/
    
    // -------------------------------------------------------------
    void setup(void)
    {
      delay(5000);
      Serial.println(F("Hello Teensy 3.6 dual CAN Test."));
    
      //Can0.setListenOnly (true); //hopefully set listen only mode
      
      Can0.begin(500000); //set baud. Change to Can1 for use on T3.6
      
      //if using enable pins on a transceiver they need to be set on
      //pinMode(2, OUTPUT);
      //pinMode(35, OUTPUT);
    
      //digitalWrite(2, HIGH);
      //digitalWrite(35, HIGH);
    }
    
    // -------------------------------------------------------------
    void loop(void)
    {
      CAN_message_t inMsg;
      while (Can0.available()) 
      {
        Can0.read(inMsg); //read message into inMsg
        if (inMsg.id == 0x288)
        Serial.print("CAN bus 0: "); 
        Serial.print(inMsg.id, HEX);
        Serial.print(", ");
        Serial.print (inMsg.buf[1], HEX);
        Serial.write('\r');
        Serial.write('\n');
      }
     }
    Any thoughts please?

  13. #163
    Junior Member
    Join Date
    Oct 2016
    Location
    Essex, England
    Posts
    5
    Hello keith-i

    Shouldn't the 'if' statement have curly brackets around the action you require to be completed, if the statement is true i.e

    if (inMsg.id == 0x288)
    { add this bracket
    Serial.print("CAN bus 0: ");
    Serial.print(inMsg.id, HEX);
    Serial.print(", ");
    Serial.print (inMsg.buf[1], HEX);
    Serial.write('\r');
    Serial.write('\n');
    } and this one

    That's what I do.

  14. #164
    Junior Member
    Join Date
    Sep 2019
    Location
    UK
    Posts
    10
    Aha, you could be right. Thanks

  15. #165
    Junior Member
    Join Date
    Aug 2019
    Posts
    12
    Looks like you've got some good answers already. I don't know if Can0.setListenOnly should go before or after the Can0.begin, but I'm sure the setup routine is where I'd put it. One thing I notice, and I don't know if it has any negative effect, but you've got a space between setListenOnly and (true). I would have thought that if this was an issue you'd get a compiler error message, but it wouldn't hurt to try without the space.

    I've actually been looking at some open source marine and NMEA200 stuff as a future project, but it sounds like you're one step ahead of me since you actually have a boat.

  16. #166
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,070
    Yes listen only SHOULD be set AFTER begin because the baudrate when set by default sets up the register with the LOM bit cleared

  17. #167
    Junior Member
    Join Date
    Sep 2019
    Location
    UK
    Posts
    10
    @Ceetee - thanks the bracket omission was the problem
    @tonton81 - I put .setListenOnly after .begin and all seems to be working now thanks

Posting Permissions

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