Forum Rule: Always post complete source code & details to reproduce any issue!
Page 17 of 17 FirstFirst ... 7 15 16 17
Results 401 to 421 of 421

Thread: FlexCAN_T4 - FlexCAN for Teensy 4

  1. #401
    Junior Member
    Join Date
    Mar 2019
    Location
    France
    Posts
    17
    Thanks alot for your fast reply
    ... I have to really switch on my brain, cause I'm still lost.

    Juste a some question : Is there 64MailBox per CAN or for 64 in total for the 3 can bus?

    I made :
    [CODE]
    FlexCAN_T4<CAN2, RX_SIZE_64, TX_SIZE_16> Can_COM1;

    void BusCan_InitMB(FlexCAN_T4* BusCan)
    {
    BusCan->setMBFilter(MB2,0x10AAFF00);
    BusCan->enhanceFilter(MB2);
    }

    void setup()
    {
    Can_COM1.begin();
    Can_COM1.setBaudRate(BAUTRATE_CAN_COM1);
    Can_COM1.setMBFilter(REJECT_ALL);
    BusCan_InitMeca(&Can_COM1);
    }
    [ /CODE]

    But the template, make me confused...
    There is of course error:
    - variable or field 'BusCan_InitMB' declared void
    - missing template arguments before 'BusCan'

    Tonton81, I know it's c++ "tips", but can I abuse more and ask for your lights?

  2. #402
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,464
    yes, each controller has 64 mailboxes, they can be changed except the CANFD mode, size depends on mailbox data capacity.

    Yes I see the error here, as a workaround until it can be figured out, the CAN frames have identifiers of which bus they came from, so you can see the received frame has msg.bus 2 set, meaning it came from CAN2

    This is why we can pass all 3 busses callbacks to one function in a user sketch and differentiate which frame came from where
    Last edited by tonton81; 10-25-2020 at 03:21 PM.

  3. #403
    Junior Member
    Join Date
    Mar 2019
    Location
    France
    Posts
    17
    To sum-up, it means, if we use CAN2.0, there are theoretically 192 (64*3) Mail Boxes ? one CAN controler per channel CAN? not sure to well undestund https://www.nxp.com/webapp/Download?colCode=IMXRT1060RM page 2515

    For my initial request, I'm totaly lost... I'will have a break and a coffee...
    But before, how could I pass all 3 busses callbacks to one function, as you said?
    In fact, my aim, is to made a recursive function, to initialised some frames to one MailBox, with a specific CAN ID (filter), and affected to one of the 3 bus. Is there an elegant way to do that?

    Again, thank a lot

  4. #404
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,464
    192 mailboxes total in CAN2.0 mode, all 3 CAN controllers, yes. each bus has 64 max.

    you can pass all your busses into one callback in your sketch. if you receive a frame from CAN2 for example, "msg.bus" will return 1 or 2 or 3, depending on if it came from bus CAN1 CAN2 or CAN3, in this case, the frame you received from CAN2 will have msg.bus set to 2, so you know it came from CAN2

  5. #405
    Junior Member
    Join Date
    Mar 2019
    Location
    France
    Posts
    17
    Ok understood, to made something generic for reading all CanX.readMB(msg) and after I check msg.bus.
    But what's happens for the init of MBs, can we do something generic/recursive? to avoid code manualy each filters MB Can1.setMBFilter(X) , Can2.setMBFilter(Y)...

  6. #406
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,464
    well filters you need to set one by one no? what do you want to configure exactly? why not use the object in the function itself? what is your purpose for the project?

  7. #407
    Junior Member
    Join Date
    Oct 2020
    Location
    Bronx
    Posts
    3
    Good info. thanks

  8. #408
    Junior Member
    Join Date
    Dec 2019
    Posts
    14
    Trying to understand message ID length, 29 bit vs 11 bit .

    MCP2551 will read standard 11 bit message ID 0x5FC but this library will read as extended 29 bit message ID 0x17F00010 .
    Same network, same data. Sending data in standard format with the library and a SN65HVD23X will keep the 11 bit standard message ID as 0x5FC and online modules will respond correctly.

    Why is this, what I'm missing ?

  9. #409
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,464
    the library reads both, that is correct. you probably didnt set the extended flag on the other library but by default both types of mailboxes extended and standard are setup to read the frames on the bus of both types on FlexCAN_T4.

  10. #410
    Junior Member
    Join Date
    Dec 2019
    Posts
    14
    Can I set the FlexCan_T4 to only show Standard?
    I figured out how to set it whenever I send data but not when receiving.

  11. #411
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,464
    yes if you want only standard frames just change the extended ones to standard. use mailboxStatus() to view the layouts and you'll know which to change. example: myCan.setMB(5, RX, STD)
    STD for standard and EXT for extended

  12. #412
    Junior Member
    Join Date
    Nov 2020
    Posts
    2
    Hi guys, 1st post (long time Embedded developer, first time teensy user).
    I'm doing some benchmarks on CAN-FD for a project - got a couple of teensy 4.1's back-to-back with skpang's breakout.
    All working great, even at 12MBits/s, so well done guys!

    Question on the timestamps... Any easy way to get the transmit TS? Maybe trigger an INT when message hits the bus to read back the TS?
    Would like to get accurate round-trip times and synchronise clocks.

    Cheers.

  13. #413
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,464
    yes it may be possible to add transmit callbacks, you can handle your own timestamp in your callback if you wish, unless you want the flexcan one specifically? then it would have to read the MB buffer but not sure if the timestamp is stored on sent, i know the transmit does have interrupt on completion though. testing would need to be done to see if we can read back the data at the time of sent mailbox and maybe return that to user callback (IF the data is still there, and IF the timestamp is modified after transmit)

  14. #414
    Junior Member
    Join Date
    Nov 2020
    Posts
    2
    It's the Tx TS recorded when the message actually makes it on the bus after any arbitration delays.

    OK, I'll look into it.

    For reference, time synchronisation over CAN:
    https://www.autosar.org/fileadmin/us...yncOverCAN.pdf

    Thanks

  15. #415
    Junior Member
    Join Date
    Nov 2020
    Posts
    4
    Can some one show me how to upload this on a teensy3.2?

  16. #416
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,464
    1) set boards manager to 3.2
    2) select FlexCAN_T4 example FIFO with interrupt
    3) in the example make sure CAN0 is set in the FlexCAN_T4 constructor

    should be fine

  17. #417
    Junior Member
    Join Date
    Nov 2020
    Posts
    4
    Quote Originally Posted by tonton81 View Post
    1) set boards manager to 3.2
    2) select FlexCAN_T4 example FIFO with interrupt
    3) in the example make sure CAN0 is set in the FlexCAN_T4 constructor

    should be fine
    Can you post a screen shot how it would look when I upload it?

    this is what im using..

    https://copperhilltech.com/teensy-3-...reakout-board/

    gm vehicle 2017

    baud 500000

    can2.0

  18. #418
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,464
    Code:
    #include <FlexCAN_T4.h>
    FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
    
    void setup(void) {
      Serial.begin(115200); delay(400);
      pinMode(6, OUTPUT); digitalWrite(6, LOW); /* optional tranceiver enable pin */
      Can0.begin();
      Can0.setBaudRate(500000);
      Can0.setMaxMB(16);
      Can0.enableFIFO();
      Can0.enableFIFOInterrupt();
      Can0.onReceive(canSniff);
      Can0.mailboxStatus();
    }
    
    void canSniff(const CAN_message_t &msg) {
      Serial.print("MB "); Serial.print(msg.mb);
      Serial.print("  OVERRUN: "); Serial.print(msg.flags.overrun);
      Serial.print("  LEN: "); Serial.print(msg.len);
      Serial.print(" EXT: "); Serial.print(msg.flags.extended);
      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();
    }
    
    void loop() {
      Can0.events();
    }

  19. #419
    Junior Member
    Join Date
    Nov 2020
    Posts
    4
    Quote Originally Posted by tonton81 View Post
    Code:
    #include <FlexCAN_T4.h>
    FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
    
    void setup(void) {
      Serial.begin(115200); delay(400);
      pinMode(6, OUTPUT); digitalWrite(6, LOW); /* optional tranceiver enable pin */
      Can0.begin();
      Can0.setBaudRate(500000);
      Can0.setMaxMB(16);
      Can0.enableFIFO();
      Can0.enableFIFOInterrupt();
      Can0.onReceive(canSniff);
      Can0.mailboxStatus();
    }
    
    void canSniff(const CAN_message_t &msg) {
      Serial.print("MB "); Serial.print(msg.mb);
      Serial.print("  OVERRUN: "); Serial.print(msg.flags.overrun);
      Serial.print("  LEN: "); Serial.print(msg.len);
      Serial.print(" EXT: "); Serial.print(msg.flags.extended);
      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();
    }
    
    void loop() {
      Can0.events();
    }
    That work THANKS.

    How can I monitor just

    Can ID 0x1F5

  20. #420
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,464
    put this at top line of canSniff function:

    if ( msg.id != 0x1F5 ) return;

    filtering it to view only specific IDs is also possible

  21. #421
    Junior Member
    Join Date
    Nov 2020
    Posts
    4
    Tonton81

    Sorry but can you do it in red on above script you did. Im trying to learn where and what function go.

    Also do you do programming? I willing to compensate you.

Posting Permissions

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