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

Thread: FlexCAN_T4 - FlexCAN for Teensy 4

  1. #801
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,832
    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,832
    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,832
    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

Posting Permissions

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