Forum Rule: Always post complete source code & details to reproduce any issue!
Page 32 of 32 FirstFirst ... 22 30 31 32
Results 776 to 791 of 791

Thread: FlexCAN_T4 - FlexCAN for Teensy 4

  1. #776
    Senior Member
    Join Date
    Dec 2016
    Montreal, Canada
    most people will pick FIFO for simplicity and ordered receptions, the FIFO example with interrupts is a good base to start with. MB is fine if you don't cared about ordered frames on the bus, mostly they will be ordered because they are read pretty fast by interrupt, FlexCAN_T4 is the successor of IFCT and supports all 3.x and 4.x teensies. the IFCT examples should work on FlexCAN_T4 as well, provided you change the header include in the sketch, and initiate the FlexCAN_T4 constructor first, along with begin()

    You should be fine though as in my car i run all 3 busses without filters using FIFO with interrupts, I doubt your handling more traffic than I am and it runs 24/7

  2. #777
    Junior Member
    Join Date
    Jun 2021
    Thx tonton81 what's the purpose of MB is this required for sending, didn't get the benefit compared to FIFO? By any chance MB is collection for multi frame message or is there some ready to use library/struct for reading such that can handle ISO 15675-2

  3. #778
    Senior Member
    Join Date
    Dec 2016
    Montreal, Canada
    FIFO is RX only, the mailboxes can be used for either transmit or receive. FIFO has ordered frames while mailboxes can receive in any order. If you are looking for consistancy, use FIFO. The FIFO with interrupt example shows you how to send/receive on CAN, you mean isotp? it's part of the library now and example is there too

  4. #779

    Having enhancedfilter problems on random extended ID's only.

    So first question is does enhanced filtering make since for a MB filter with one ID? I think the answer is it does not matter because it should not bleed through,

    But for MB filter with multiple ID it should stop any bleed through frames correct?

    So as I explained before I am reading in a DBC file and parting out the messages and signals.

    From there, based on the DBC file messages ID's I am either setting up STD and/or EXT receive mail boxes (up to 60 based on the # of messages).
    If there are more than 60 ID's then I double up the highest value (lowest priority ID's) in the MB filtering.
    When I assign the ID(s) to the MB I store what message index(es) are applied to the filter for each of the RX mailboxes.
    So when I receive message and the interrupt fires I copy the important frame data to a structure, set a received flag for that structure and clear interrupt. Each controller has it own receive structure. I process the received frame in the loop and clear the flag.
    To process the received from I use the receiving MB (tracked for each controller MD filter ID assignment) to find the ID index based on the previous stored information from when the MB filter was set up.
    This could be 1 or 2 ID's but the list to search is short.
    Then I have a back up binary sort if something fall through the cracks and if the index of the ID applied the filter to not line up with the MB filter.
    Based on the received message ID I process the signals in the based on the signal indexes associated with the message ID(or search for the PID and based on the PID process the signals assigned to the PID).

    Sorry that was a lot but I wanted you to understand the basic structure of what I was trying to do as I do not want the micro the spend all its time searching for message ID's to find the correct signals/PID to process.

    So what I ran the above code with and 500K standard ID's, with 1 traffic source feeding into all the controller on the Teensy it all worked great.

    I was playing back more than 600 frames/second of recorded real vehicle data which means the micro was receiving the exact same frames at the same time so the interrupt setting all 3 at the same time. I figured this was a worst case scenario because in reality the incoming frames on each of the CAN controllers would be random.

    So I was doing all the above to > 1800 frames per second. I was keeping each time a frame was processed and was outputting a count every 5000 (all 3 can controllers combined.

    I was watching SavvyCAN frame send count and every 1600 ish frames I would see another 5000 count output. So after feeding individual frame and verifying the signal calculations against SavvyCAN and running the full bore recorded bus content I felt pretty good.

    So then I ventured into confirming the calculations for individual J1939 extended ID's (still using the standard MB filter not user).

    Then I lost all confidence. It seems that I am getting random hit and miss with the enhanced filtering. I randomly grabbed some high and low priority ID's and tried but it I can not see any rhyme or reason.

    As soon as I comment out the myCAN[channel]->enhanceFilter((FLEXCAN_MAILBOX)i) it goes is received and process correctly.

    I double checked the DBC vs what SavvyCAN was sending out by bypassing all the filter and letting binary search find the ID and sure enough as soon as I did that all the ID's were received as expected and processed.

    But the whole point of the above I do not want to have the micro spend its' time searing for and ID match in a 60+ ID's every time a message is received. I thought that is was the filtering was meant to avoid. To not have the micro do frivolous clock cycles.

    Why do you think the enhanced filtering is hit and miss for extended frames?



  5. #780
    Senior Member
    Join Date
    Dec 2016
    Montreal, Canada
    enhancedfilter was not meant for custom user filters, only the automatic filtering as it's ID based masking based off ANDing the calculated mask, a custom mask on the other hand, ANDing the mask with the ID might allow it to pass or fail, it wasn't designed for user masking


    a stored id & *same_mask* must == a received id & *same_mask*

  6. #781
    As I said, I am not using userfilter .

    I am uisng
    myCAN[channel]->setMBFilter((FLEXCAN_MAILBOX)i, id1, id2);
    myCAN[channel]->setMBFilter((FLEXCAN_MAILBOX)i, id1)

  7. #782
    Senior Member
    Join Date
    Dec 2016
    Montreal, Canada
    so unneeded id's are bleeding through? and did you make sure all other mailboxes are setup, or refusing messages with exception ids, if a couple of message boxes have the same id & filter, other mailboxes may accept it if it fits their filter criteria

  8. #783
    I put a few Serial print statement in your code to see what was going on in the
    filter_match(FLEXCAN_MAILBOX mb_num, uint32_t id)

    Something is getting garbled in
    I am printing out the both sides of
    id == mb_filter_table[mb_num][i+1]
    When I do get a match I see

    Got Frame CAN2
    18.309938,Bus:2,ID:CF00400,Overun:false,MB:56,Len: 8,30,0,0,0,1C,0,0,0
    Engine_Demand_Percent_Torque: UINT32_T 0 -, Source_Address_of_Controller_Dev: UINT32_T 0 -, Engine_speed:896.0000 rpm, Actual_Engine_Percent_Torque:-125.0000 %, Drivers_Demand_Engine_Percent_To:-125.0000 %, Engine_and_Retarder_Torque_Mode: UINT32_T 0 -,
    Everything is good.

    When I don't see a match I get

    ox18FED900 is the recieved ID
    0x18FEFB03 is coming out of the filter table.

    I have no idea where that comes from as my ID's assinged to MB are
    CAN 2 RX MB Assignement(MB Type|MB#:ID)
    4 : FF | 0 : 1CFEF803,1CFEF803/1 : 1CFEBE00,1CFEBE00
    5 : FF | 2 : 1CECFF0B,1CECFF0B/3 : 1CECFF00,1CECFF00
    6 : FF | 4 : 1CEBFF0B,1CEBFF0B/5 : 1CEBFF03,1CEBFF03
    7 : FF | 6 : 1CEBFF00,1CEBFF00/7 : 18FF5800,18FF5800
    8 : FF | 8 : 18FF5000,18FF5000/9 : 18FF4F00,18FF4F00
    9 : FF | 10 : 18FF4E00,18FF4E00/11 : 18FF4D00,18FF4D00
    10 : FF | 12 : 18FF3F00,18FF3F00/13 : 18FF3D00,18FF3D00
    11 : FF | 14 : 18FF3C00,18FF3C00/15 : 18FF3B00,18FF3B00
    12 : FF | 16 : 18FF3A00,18FF3A00/17 : 18FF3900,18FF3900
    13 : FF | 18 : 18FF3800,18FF3800/19 : 18FF3700,18FF3700
    14 : FF | 20 : 18FF3600,18FF3600/21 : 18FF3300,18FF3300
    15 : FF | 22 : 18FF3018,18FF3018/23 : 18FF2A17,18FF2A17
    16 : FF | 24 : 18FF2517,18FF2517/25 : 18FF2300,18FF2300
    17 : FF | 26 : 18FF1702,18FF1702/27 : 18FF1002,18FF1002
    18 : FF | 28 : 18FF1000,18FF1000/29 : 18FF0B00,18FF0B00
    19 : FF | 30 : 18FF0A00,18FF0A00/31 : 18FF0900,18FF0900
    20 : FF | 32 : 18FF0800,18FF0800/33 : 18FF0700,18FF0700
    21 : FF | 34 : 18FF0300,18FF0300/35 : 18FF0200,18FF0200
    22 : FF | 36 : 18FF0000,18FF0000/37 : 18FEFB03,18FEFB03
    23 : FF | 38 : 18FEF117,18FEF117/39 : 18FEF10B,18FEF10B
    24 : FF | 40 : 18FEF100,18FEF100/41 : 18FEEE00,18FEEE00
    25 : FF | 42 : 18FEEB0B,18FEEB0B/43 : 18FEEB03,18FEEB03
    26 : F0 | 44 : 18FEE518,18FEE518
    27 : F0 | 45 : 18FEE203,18FEE203
    28 : F0 | 46 : 18FEDF00,18FEDF00
    29 : F0 | 47 : 18FEDA0B,18FEDA0B
    30 : F0 | 48 : 18FEDA03,18FEDA03
    31 : F0 | 49 : 18FED900,18FED900
    32 : F0 | 50 : 18FECA0B,18FECA0B
    33 : F0 | 51 : 18FECA03,18FECA03
    34 : F0 | 52 : 18FEBF0B,18FEBF0B
    35 : F0 | 53 : 18FEAE17,18FEAE17
    36 : F0 | 54 : 18FE4B03,18FE4B03
    37 : F0 | 55 : 18FE4A03,18FE4A03
    38 : F0 | 56 : 18FDA403,18FDA403
    39 : F0 | 57 : 18FDA400,18FDA400
    40 : F0 | 58 : 18FD9503,18FD9503
    41 : F0 | 59 : 18FD7C00,18FD7C00
    42 : F0 | 60 : 18F00C03,18F00C03
    43 : F0 | 61 : 18F00503,18F00503
    44 : F0 | 62 : 18F0010B,18F0010B
    45 : F0 | 63 : 18F00029,18F00029
    46 : F0 | 64 : 18EF1817,18EF1817
    47 : F0 | 65 : 18EF1718,18EF1718
    48 : F0 | 66 : 18EF1700,18EF1700
    49 : F0 | 67 : 18EF0503,18EF0503
    50 : F0 | 68 : 18EF0017,18EF0017
    51 : F0 | 69 : 18EEFF0B,18EEFF0B
    52 : F0 | 70 : 18EEFF03,18EEFF03
    53 : F0 | 71 : 18EAFF0B,18EAFF0B
    54 : F0 | 72 : 18EAFF03,18EAFF03
    55 : F0 | 73 : CFF0100,CFF0100
    56 : F0 | 74 : CF00400,CF00400
    57 : F0 | 75 : CF00300,CF00300
    58 : F0 | 76 : CF00203,CF00203
    59 : F0 | 77 : C01030B,C01030B
    60 : F0 | 78 : C00290B,C00290B
    61 : F0 | 79 : C000012,C000012
    62 : F0 | 80 : C000003,C000003
    63 : F0 | 81 : 8FE6E0B,8FE6E0B
    I have a "0x18FEFB03" assigned to MB 22 but "0x8FED900" is assigned to MB 31.

    Something is not correct with that? Wrong ID in the wrong table entry?

    Again first set of ID come out the mb_filter_table[mb_num][i+1] the one after the "/" is "id".

    I tried a doubled up MB9 which I have loaded ID's 0x18FF4E00 and 0x18FF4D00 into.
    This is what I get out of the filter_match print statments:
    Neither of the ID's stored in "mb_filter_table" are any of the id's which used for MB filter.

    It looks like somehow some for stored ID's in "mb_filter_table" are getting 0x100 added and some are not?



    Last edited by bvernham; 06-17-2021 at 06:36 PM. Reason: Update

  9. #784
    See my next post...there are no duplicate ID's.

    The point is I am receiving some messages but not others when enhanced filter is on.

    Don't enable enhanced filter, it is received as expected.

    I am "REJECT_ALL" before I am setting up each individual MB filter with one or two ID's


  10. #785

    Going deeper on "mb_filter_table[mb_num][i+1]"

    So just to make sure I was not messing something up I did this:
    FCTP_FUNC bool FCTP_OPT::setMBFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2) {
      if ( mb_num < mailboxOffset() || mb_num >= FLEXCANb_MAXMB_SIZE(_bus) ) return 0; /* mailbox not available */
      if ( (FLEXCAN_get_code(FLEXCANb_MBn_CS(_bus, mb_num)) >> 3) ) return 0; /* exit on TX mailbox */ 
      uint32_t mask = ( !(FLEXCANb_MBn_CS(_bus, mb_num) & FLEXCAN_MB_CS_IDE) ) ? FLEXCAN_MB_ID_IDSTD(((id1 | id2) ^ (id1 & id2)) ^ 0x7FF) : FLEXCAN_MB_ID_IDEXT(((id1 | id2) ^ (id1 & id2)) ^ 0x1FFFFFFF);
      filter_store(FLEXCAN_MULTI, mb_num, 2, id1, id2, 0, 0, 0);
      return 1;
    And when I run the set up with this in place with my MB set up debugging enabled I get:

    9 : FF | 10 : 18FF4E00,18FF4E00/11 : 18FF4D00,18FF4D00
    Exactly what is expected.

    Both "id1" and "id2" go into the function and are unaltered prior to entering
    filter_store(FLEXCAN_MULTI, mb_num, 2, id1, id2, 0, 0, 0);
    In my debug output the 9 means MB9, $FF means extended, double filter (nothing to do with any input into your code) . The 10 and 11 are first the id indexes for the message structure. The the "id1","id1"/"id2","id2" are showing the id1 entered into the "setMBFilter(" and that of the index stored in the MB structure ( am keeping track of what id indexes are applied to each MB filter).

    So again, this is all good.

    But when I send a frame with "0x18FF4E00" which is exactly what is stored in MB9.

    As I said before I added print statement into your code for:
    FCTP_FUNC volatile bool FCTP_OPT::filter_match(FLEXCAN_MAILBOX mb_num, uint32_t id) {
      if ( !(mb_filter_table[mb_num][0] & 0x10000000) ) return 1;
      if ( (mb_filter_table[mb_num][0] >> 29) == FLEXCAN_MULTI ) {
        for ( uint8_t i = 0; i < ((mb_filter_table[mb_num][0] & 0x380) >> 7); i++) 
    		if ( id == mb_filter_table[mb_num][i+1] ) return 1;
      else if ( (mb_filter_table[mb_num][0] >> 29) == FLEXCAN_RANGE ) {
        if ( id >= mb_filter_table[mb_num][1] && id <= mb_filter_table[mb_num][2] ) return 1;
      else if ( (mb_filter_table[mb_num][0] >> 29) == FLEXCAN_USERMASK ) {
        for ( uint8_t i = 1; i < ((mb_filter_table[mb_num][0] & 0x380) >> 7) + 1; i++) {
          if ( (id & mb_filter_table[mb_num][5]) == (mb_filter_table[mb_num][i] & mb_filter_table[mb_num][5]) ) return 1;
      return 0;
    I get the below:

    What is being in "setMBFilter(" is not what is ending up in
    I can the stored ID's get modified?



  11. #786
    Senior Member
    Join Date
    Dec 2016
    Montreal, Canada
    hmm that is indeed weird, yes if you want to try modifying the table move it from private to public, maybe after you set all the IDs and filters you can print out the table list so you can cross verify everything, I am not home to test this out but also try to make the table volatile, not sure if it will help but i would try to check what IDs we set are registered in the table and if it doesn't match it needs to be corrected. Like you said it works in one way but not another, which is weird, the IDs are not computed or modified in any way and should be put into the table for lookup as is, so if they are wrong, needs to be corrected

  12. #787
    Well, the table is already volatile
    volatile uint32_t mb_filter_table[64][6];

    Will move public and see if I can get it to list out.

    OK so after I finish assigning all the MB filters, I am listing out the message ID corresponding to the index(es) stored corresponding each MB.

    cout << F("RX MB ") << dec << (uint16_t)(i);
            if (mb[j][i].single & MBSingEXTOffset) cout << F(" EXT");//Extended Recieve Frame
            else cout << F(" STD");//Starndard Recieve Frame
            cout << F(" ID: ");
            if ((mb[j][i].single & MBSingMultiOffset)) {
              cout << dec << (uint16_t)mb[j][i].StartMessage << F(":") << uppercase << hex << messages[j][mb[j][i].StartMessage].ID << F(",") << Can2.mb_filter_table[i][1] << F("/") << dec << (uint16_t)mb[j][i].EndMessage << F(":") << uppercase  << hex << messages[j][mb[j][i].EndMessage].ID << F(",") << Can2.mb_filter_table[i][2] << endl; //two ID Filter MB
            else cout << dec << (uint16_t)mb[j][i].StartMessage << F(":") << uppercase << hex << messages[j][mb[j][i].StartMessage].ID << F(",") << Can2.mb_filter_table[i][1]<< endl; //Single ID Filtered MB
          cout << endl;
    I could not figure out how to go from Can2 to myCAN[1]-> When I tried putting the

    virtual volatile uint32_t mb_filter_table[64][6] = 0;

    Did not like it so I went with "Can2" for expeciancy.

    CAN 2 RX MB Assignement(#:ID)
    RX MB 4 EXT ID: 0:1CFEF803,1CFEF803/1:1CFEBE00,1CFEBE00
    RX MB 7 EXT ID: 6:1CEBFF00,1CEBFF00/7:18FF5800,18FF5800
    RX MB 8 EXT ID: 8:18FF5000,18FF5000/9:18FF4F00,18FF4F00
    RX MB 9 EXT ID: 10:18FF4E00,18FF4E00/11:18FF4D00,18FF4D00
    RX MB 10 EXT ID: 12:18FF3F00,18FF3F00/13:18FF3D00,18FF3D00
    RX MB 11 EXT ID: 14:18FF3C00,18FF3C00/15:18FF3B00,18FF3B00
    RX MB 12 EXT ID: 16:18FF3A00,18FF3A00/17:18FF3900,18FF3900
    RX MB 13 EXT ID: 18:18FF3800,18FF3800/19:18FF3700,18FF3700
    RX MB 14 EXT ID: 20:18FF3600,18FF3600/21:18FF3300,18FF3300
    RX MB 15 EXT ID: 22:18FF3018,18FF3018/23:18FF2A17,18FF2A17
    RX MB 16 EXT ID: 24:18FF2517,18FF2517/25:18FF2300,18FF2300
    RX MB 17 EXT ID: 26:18FF1702,18FF1702/27:18FF1002,18FF1002
    RX MB 18 EXT ID: 28:18FF1000,18FF1000/29:18FF0B00,18FF0B00
    RX MB 19 EXT ID: 30:18FF0A00,18FF0A00/31:18FF0900,18FF0900
    RX MB 20 EXT ID: 32:18FF0800,18FF0800/33:18FF0700,18FF0700
    RX MB 21 EXT ID: 34:18FF0300,18FF0300/35:18FF0200,18FF0200
    RX MB 22 EXT ID: 36:18FF0000,18FF0000/37:18FEFB03,18FEFB03
    RX MB 23 EXT ID: 38:18FEF117,18FEF117/39:18FEF10B,18FEF10B
    RX MB 24 EXT ID: 40:18FEF100,18FEF100/41:18FEEE00,18FEEE00
    RX MB 25 EXT ID: 42:18FEEB0B,18FEEB0B/43:18FEEB03,18FEEB03
    RX MB 26 EXT ID: 44:18FEE518,18FEE518
    RX MB 27 EXT ID: 45:18FEE203,18FEE203
    RX MB 28 EXT ID: 46:18FEDF00,18FEDF00
    RX MB 29 EXT ID: 47:18FEDA0B,18FEDA0B
    RX MB 30 EXT ID: 48:18FEDA03,18FEDA03
    RX MB 31 EXT ID: 49:18FED900,18FED900
    RX MB 32 EXT ID: 50:18FECA0B,18FECA0B
    RX MB 33 EXT ID: 51:18FECA03,18FECA03
    RX MB 34 EXT ID: 52:18FEBF0B,18FEBF0B
    RX MB 35 EXT ID: 53:18FEAE17,18FEAE17
    RX MB 36 EXT ID: 54:18FE4B03,18FE4B03
    RX MB 37 EXT ID: 55:18FE4A03,18FE4A03
    RX MB 38 EXT ID: 56:18FDA403,18FDA403
    RX MB 39 EXT ID: 57:18FDA400,18FDA400
    RX MB 40 EXT ID: 58:18FD9503,18FD9503
    RX MB 41 EXT ID: 59:18FD7C00,18FD7C00
    RX MB 42 EXT ID: 60:18F00C03,18F00C03
    RX MB 43 EXT ID: 61:18F00503,18F00503
    RX MB 44 EXT ID: 62:18F0010B,18F0010B
    RX MB 45 EXT ID: 63:18F00029,18F00029
    RX MB 46 EXT ID: 64:18EF1817,18EF1817
    RX MB 47 EXT ID: 65:18EF1718,18EF1718
    RX MB 48 EXT ID: 66:18EF1700,18EF1700
    RX MB 49 EXT ID: 67:18EF0503,18EF0503
    RX MB 50 EXT ID: 68:18EF0017,18EF0017
    RX MB 51 EXT ID: 69:18EEFF0B,18EEFF0B
    RX MB 52 EXT ID: 70:18EEFF03,18EEFF03
    RX MB 53 EXT ID: 71:18EAFF0B,18EAFF0B
    RX MB 54 EXT ID: 72:18EAFF03,18EAFF03
    RX MB 55 EXT ID: 73:CFF0100,CFF0100
    RX MB 56 EXT ID: 74:CF00400,CF00400
    RX MB 57 EXT ID: 75:CF00300,CF00300
    RX MB 58 EXT ID: 76:CF00203,CF00203
    RX MB 59 EXT ID: 77:C01030B,C01030B
    RX MB 60 EXT ID: 78:C00290B,C00290B
    RX MB 61 EXT ID: 79:C000012,C000012
    RX MB 62 EXT ID: 80:C000003,C000003
    RX MB 63 EXT ID: 81:8FE6E0B,8FE6E0B

    So if you look at MB9 it all looks good.

    Again I send out 18FF4E00 the filter table entry is getting changed in between the entry and the message reception????

    Set Up Done!


    Last edited by bvernham; 06-18-2021 at 01:44 AM. Reason: Update

  13. #788
    Got it, it is not matching on the correct MB;

    It is supposed to match on MB9:

    RX MB 8 EXT ID: 8:18FF5000,18FF5000/9:18FF4F00,18FF4F00
    RX MB 9 EXT ID: 10:18FF4E00,18FF4E00/11:18FF4D00,18FF4D00

    Even with some single frame filter is is missing the expected MB?

    MB22 is hitting when it should be MB31
    RX MB 31 EXT ID: 49:18FED900,18FED900

    How can it get a single filtered MB wrong?



  14. #789
    Senior Member
    Join Date
    Dec 2016
    Montreal, Canada
    not sure I havn't faced this issue before or looked at it yet, ok, you dont need a base class if you use the template object directly to print the table, just make it public and use Can1.mb_filter_table[x][x] or whatever name you used in constructor

    Think of the base class as a limited symbolic link to the constructor template object. The template object has full debug over the flexcan_t4 class but the base class only has selected functions which it could have access to.

  15. #790
    distribute() seems to fix the issue.

    With distribute and enhanced filter does it matter what ID I assign (via filter) to what MB?

    Should I put the higher priority ID's (lower numerical value) to the lower numerical value MB's?

    Does it matter?

    Seems like I am banging on all cylinders!

    Did stress test with ~23,400 frames giving ~ 117,285 signals/second. No overflows.




  16. #791
    Senior Member
    Join Date
    Dec 2016
    Montreal, Canada
    the lowest mailbox (granted they are free to receive) receives first, the last mailbox (if all full) always gets overridden if overflow occurs. If a message is destinated for one mailbox only, and no other mailboxes accept that same frame, then that mailbox will overflow and override the holding message

    the SMB (serial message buffer, hardware) goes from small MB0 to largest MB64 to search for an acceptable free slot that is allowed to save a message to, if none accept it, the SMB tosses it to begin receiving next frame

Posting Permissions

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