Forum Rule: Always post complete source code & details to reproduce any issue!
Page 33 of 33 FirstFirst ... 23 31 32 33
Results 801 to 814 of 814

Thread: FlexCAN_T4 - FlexCAN for Teensy 4

  1. #801
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,850
    yeah it's still open on github's issue tracker, a user requested it so i added it in

    Code:
          CAN_error_t error; /* create a message struct to store the queue details, for data accesses */
          if ( Can1.error(error, 1) ) { // overload 1 means internally print everything in error event to serial monitor
            // Do Something...
            if ( error.ACK_ERR ) Serial.print("ACK error occured");
            if ( !strcmp(error.state, "Transmitting") ) Serial.println("TRANSMITTING!");
          }


    I've added the commits for error reporting, try it out
    (me hot-plugging the esp32 and reconnecting)

    Code:
    FlexCAN State: Receiving, FLT_CONF: Error Active
    FlexCAN State: Idle, FLT_CONF: Error Active
    FlexCAN State: Transmitting, FLT_CONF: Error Active
    FlexCAN State: Transmitting, ACK_ERR, FLT_CONF: Error Active
    FlexCAN State: Transmitting, ACK_ERR, TX_WRN: 96, FLT_CONF: Error Active
    FlexCAN State: Transmitting, ACK_ERR, TX_WRN: 104, FLT_CONF: Error Active
    FlexCAN State: Transmitting, ACK_ERR, TX_WRN: 128, FLT_CONF: Bus off
    FlexCAN State: Transmitting, TX_WRN: 127, FLT_CONF: Error Active
    FlexCAN State: Transmitting, FLT_CONF: Error Active
    FlexCAN State: Receiving, FLT_CONF: Error Active
    FlexCAN State: Idle, FLT_CONF: Error Active
    FlexCAN State: Transmitting, FLT_CONF: Error Active

  2. #802
    Junior Member
    Join Date
    Jun 2021
    Location
    Germany
    Posts
    12
    can you please give usage example for ext_output1()

    I use your sketch CAN2.0_example_FIFO_with_interrupts.ino and don't know how to do it right. Currently I have placed my code inside canSniff() which is probably not intended this way.

    I have something to show meanwhile (it works but i don't like it)
    https://gitlab.com/aIecxs/w211-ac-control

  3. #803
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,850
    ext_output1() is a background callback same as canSniff, it's intended for other libraries to access CAN data (isotp) without needing to add more sketch code to forward objects

    putting your code in canSniff is correct way, if it gets too cluttered you could make sub function calls from the callback

    bit more complex, you could also do individual mailbox filtering if you want each mailbox to receive a specific ID in it's own canSniff callback

    KOMP_STELL should be volatile char
    timeout should be volatile unsigned long, not long

    variables that share both ISR (canSniff) and loop should be declared volatile, however,

    if you are using Can.events(), voltaile is not needed. If you comment out events(), they should be volatile since theyll be from interrupt context
    Last edited by tonton81; 07-25-2021 at 06:06 PM.

  4. #804
    Junior Member
    Join Date
    Jun 2021
    Location
    Germany
    Posts
    12
    Thanks for that hints, really appreciate it!

    Although I don't understand what Can.events() does I believe I should keep it in main. I added sub function and changed integer types as suggested, but when try to set volatile struct I get compiler warnings. If you know how to fix feel free to send me commit.

    Have another issue with memcpy. I don't know how to map msg.buf into bit fields. It works fine with full bytes (uint8_t) and I receive KOMP_STELL correctly that means byte order is okay. I can even map single byte in little endian and receive bits (bool) for each 8-bit series in right order too. But it starts to fail for odd-numbered bit field size and empty paddings. I read here that we should use bit-wise operators instead, so I think I can throw my last commit into garbage.

    Do you have any other template how to map msg.buf, for example bit-wise operator?
    here is some example output of canSniff() https://pastebin.com/p4QuFHsn

  5. #805
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,850
    i use something simple

    msg.buf[1] & (1U << 3)

    this gives you the bool at bit position 3 (from the right, of course)

    1U basically checks if it matches if bit is set (unsigned), left shifted 3 times

  6. #806
    Senior Member
    Join Date
    Feb 2015
    Posts
    131
    So I am trying to figure out how to use the ISO-TP with the present frame work I have.

    I am using the MB filtering to minimize the # of message ID (or a single ID if<60 ID's) that I have to search through so a maximum 2 ID assigned to a specific MB.

    The ISO-TP config does not report MB nor does it report the bus to which call back is originated from.

    The other issue there is broadcasted data on the same bus as the OBD data so for example mode 9 which requires iso-TP.

    For ISO-TP "if ( msg.buf[0] <= 7 ) { /* single frame */ " but we have no idea what msg.buf[0] will be in the case of broad cast can data.

    So not quite sure how we can have this implementation when there is broadcast data.

    Please let me know you thoughts.

    Thanks

    Bruce

  7. #807
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,850
    you can comment out and disable if you don't want to receive single frames that you can just handle in your normal callback, if length is less than 7. The bus is assigned in the constructor as well as the callback, so the callback you'd assume the correct bus, but in terms of mailboxes, if the frames come from multiple mailboxes, how can it tell you where it came from? that would need to store even more data and mailbox counts in a bigger payload, making even more complex code.

  8. #808
    Senior Member
    Join Date
    Feb 2015
    Posts
    131
    When I parse the DBC file I know what ID's have PIDS associated with them. If there is more than one ID with PIDS then those are assigned to another set of PIDS.

    The ID are assigned to mail boxes as normal with 2 at the most. When the ID is matched in memory it also has a flag stating is has PIDS. Those PIDS are stored in it. You can up to 8 ECU's associated with a bus so you could have up to 8 ID of which multiple PIDs may respond to information ID's like CAL ID.CVN/ECU name so you would need the ability to handle this anyways. If you have 8 ECU's you could have 4 to 8 MB's associated with those ID's but you could have 8 ECU names so you would need to be able each of those separately anyways.

    Bruce

  9. #809
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,850
    if they have a different CANID, they are assembled in parallel as the frames come in, the data is just appended to the queue, why would you bind a certain mailbox to a payload? i guess you could take the last MB frame issued and use that as a source of the frames before hitting the callback..

  10. #810
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    698
    What's random doing in this method?
    https://github.com/tonton81/FlexCAN_...AN_T4.tpp#L942

    Code:
    FCTP_FUNC int FCTP_OPT::read(CAN_message_t &msg) {
      bool _random = random(0, 2);
      if ( ( !_random ) && ( FLEXCANb_MCR(_bus) & FLEXCAN_MCR_FEN ) &&
           !( FLEXCANb_IMASK1(_bus) & FLEXCAN_IMASK1_BUF5M ) &&
           ( FLEXCANb_IFLAG1(_bus) & FLEXCAN_IFLAG1_BUF5I ) ) return readFIFO(msg);
      return readMB(msg);
    }
    I can see that it would only occasionally trigger return readFIFO(msg), but I don't understand why it's setup this way.

  11. #811
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,850
    it's just to pick between either mailbox or fifo at random.
    if fifo isn't enabled it will just fall down to read mailboxes only.
    readMB wont do anything as the function returns if you have no reception, only tx mailboxes.

    you can either readFIFO or readMB, I decided to pick at random because if one is always receiving, lets say FIFO is always pulling for every check, the mailbox would probably not be read as often, especially with slow user code.

    Obviously these 3 methods are for polling only. If you have interrupts enabled, they simply would return as they don't read interrupt enabled mailboxes

  12. #812
    Senior Member
    Join Date
    Feb 2015
    Posts
    131
    Yes, I use it exclusively for my teensy 4.1 application.

  13. #813
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    698
    How do we emit messages with an extended id? Do we just set the CAN_message_t id field or is there some setup that's needed first?

  14. #814
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,850
    Code:
    msg.flags.extended = 1:

Posting Permissions

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