Forum Rule: Always post complete source code & details to reproduce any issue!
Page 29 of 32 FirstFirst ... 19 27 28 29 30 31 ... LastLast
Results 701 to 725 of 791

Thread: FlexCAN_T4 - FlexCAN for Teensy 4

  1. #701
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,803
    try = &Can1 ? the ampersand

  2. #702
    Quote Originally Posted by tonton81 View Post
    try = &Can1 ? the ampersand
    Code:
    static FlexCAN_T4_Base* myCAN[3] = { nullptr };
    FlexCAN_T4<CAN1, RX_SIZE_2, TX_SIZE_16> Can0;
    FlexCAN_T4<CAN2, RX_SIZE_2, TX_SIZE_16> Can1;
    FlexCAN_T4<CAN3, RX_SIZE_2, TX_SIZE_16> Can2;
    
    bool StartCAN()
    {
      myCAN[0] = &Can0;
      myCAN[1] = &Can1;
      myCAN[2] = &Can2;
      myCAN[1].begin();
      return true;
    }
    Well that compiled fine until I tried to do something with it like add begin
    error: request for member 'begin' in 'myCAN[1]', which is of pointer type 'FlexCAN_T4_Base*' (maybe you meant to use '->' ?)
    myCAN[1].begin(); ^
    So change
    .
    to
    ->
    :

    Then I get the following:
    'class FlexCAN_T4_Base' has no member named 'begin'
    myCAN[1]->begin();
    ^
    Which makes send because FlexCAN_T4_Base doesn't have a begin.

    "FCTP_CLASS class FlexCAN_T4 : public FlexCAN_T4_Base {
    has a begin.

    But the above mimic
    _CAN1->setBaudRate(currentBitrate, (( FLEXCANb_CTRL1(_bus) & FLEXCAN_CTRL_LOM ) ? LISTEN_ONLY : TX));
    So like I said this is stretching my knowledge to the limit.

    Thanks

    Bruce

  3. #703
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,803
    the base class has basic virtual functions. use the regular templated objects for setting up the bus, use the pointers to write to the buses

  4. #704
    Quote Originally Posted by tonton81 View Post
    the base class has basic virtual functions. use the regular templated objects for setting up the bus, use the pointers to write to the buses
    There is no way to use the templated objects in such a manner.

    Otherwise going to have to set up a lot if "case statement" to go through the set up of all 3 buses.

    Any other thought on how to set this up on in a loop in a more efficient way than case statement?

    Thanks

    Bruce

  5. #705
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,803
    what exactly do you want to set on 3 controllers at the same time? trying to figure out why you need to symmetrically control 3 ports?

  6. #706

    myCAN[i]

    Quote Originally Posted by tonton81 View Post
    what exactly do you want to set on 3 controllers at the same time? trying to figure out why you need to symmetrically control 3 ports?
    I want to set everything up in a loop.

    I have possibly 3 DBC files on the SD card. Read in and parsed into a structure. If there are PID's in the DBC file, the message ID is in a certain range so those are parsed into a PID structure.

    So essentially you have DBC -> Message-> Signal or DBC -> Message - > PID -> Signal

    So I am setting this up so the reception is in mail boxes so only 1 or two messages will get filtered for reception in each mail boxes so essentially the calculation path becomes:

    MB ->Message->Signal or MB ->Message - >PID ->Signal with the calculation result stored in the signal structure for logging.

    Thanks

    Bruce

  7. #707
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,803
    Ok but why do you need to run begin() in a for loop? signal sending with write() works with the base class

  8. #708

    begin() in a for loop

    Quote Originally Posted by tonton81 View Post
    Ok but why do you need to run begin() in a for loop? signal sending with write() works with the base class
    I am only setting up a controller if there is a corresponding DBC file.

    So if the DBC file has no messages (no file) then I am not setting up that controller.

    I have no idea which can controller the user will have hooked up to what speed/protocol/frame size and so on so I am figuring that all out based on the DBC file being placed on the SD card.

    For example, there is nothing that does not allow both standard and extended frames on the same bus so if the DBC file has both and there are more messages than mail boxes I need to divide the MB up based on how many of each ID (STD or EXT) there is and from there, based on message priority I assign one of two messages to each MB via the filter. This way when the mail box is received I only need to look at one to two messages to see which signals I need to decode.

    Do it all a look just makes for more compact, readable code.

    Just a preference, not a must.

    Hope that helps answer your question.

    Thanks

    Bruce

  9. #709
    Junior Member
    Join Date
    Nov 2020
    Posts
    1
    Hi Tony! What can you recommend to use to implement a can relay in real car can network? I've tried to run different versions of the forwarding code on Teensy 3.6 with hvd230 using FlexCan_T4. But it seems 99% of frames was lost or distorted. So I couldn't just get and translate the same frame from CAN1 to CAN2 and vv. Technically it was a relay between odb2 and elm327 adapter and I'm sure all the connections was correct. Thanks in advance for any help.

  10. #710
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,803
    remove events() from the loop() use interrupts and bump the controller to 60MHz using setClock()

    bvernham, try adding the functions you think you'll be using in the base class, they must match the template class function but set as virtual so the template can override, check if that will work with your CAN pointers

  11. #711
    set as virtual so the template can override


    They don't have a "mind blown emoji".....

    Code:
    class FlexCAN_T4_Base {
    so got the base class

    Got the
    Code:
    FCTP_CLASS class FlexCAN_T4 : public FlexCAN_T4_Base {
    templated class

    So
    class FlexCAN_T4_Base {
    virtual void begin();
    virtual void setBaudRate(uint32_t baud = 1000000, FLEXCAN_RXTX listen_only = TX);
    and so on?

    Thanks

    Bruce

  12. #712
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,803
    yes but for virtual functions you must use " = 0"

  13. #713
    Quote Originally Posted by tonton81 View Post
    yes but for virtual functions you must use " = 0"
    Code:
    class FlexCAN_T4_Base {
    virtual void begin() = 0;
    virtual void setBaudRate(uint32_t baud = 1000000, FLEXCAN_RXTX listen_only = TX) = 0;


    Thanks

    Bruce

  14. #714
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,803
    yup, pretty much

  15. #715
    bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t mask);
    bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2, uint32_t mask);
    bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2, uint32_t id3, uint32_t mask);
    bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2, uint32_t id3, uint32_t id4, uint32_t mask);

    Where are these stashed?

    I can't find them in the FlexCAN_T4.h.

    Thanks

    Bruce

  16. #716
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,803
    it's in there, search for it, you are probably looking in wrong template class, CAN & CANFD have a different class, but I don't think that will work because to be a base class both will have to have the identical functions to have a virtual function call and only CAN2.0 has the function. If it does fail to compile though, you can put a dummy function in the CANFD class so it matches the CAN2.0 class and put the semi-colon surrounded by brackets "{;}", this will create an empty function for the FD side

    Do you plan to use every single function? ��
    Last edited by tonton81; 05-30-2021 at 04:35 AM.

  17. #717

    We are both right on this one.....

    Quote Originally Posted by tonton81 View Post
    it's in there, search for it, you are probably looking in wrong template class, CAN & CANFD have a different class, but I don't think that will work because to be a base class both will have to have the identical functions to have a virtual function call and only CAN2.0 has the function. If it does fail to compile though, you can put a dummy function in the CANFD class so it matches the CAN2.0 class and put the semi-colon surrounded by brackets "{;}", this will create an empty function for the FD side

    Do you plan to use every single function? ��
    Well you are right because it is in github.

    I am right because it was not packaged with Teensyduino.

    Which also makes sense because when I compiled some examples I got compiler warnings.

    No, I am not using all of the just the key ones associated with MB and to disable FIFO.

    Thanks

    Bruce

  18. #718
    Code:
    FCTPFD_CLASS class FlexCAN_T4FD : public FlexCAN_T4_Base {
      public:
    virtual bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2, uint32_t id3, uint32_t id4, uint32_t mask) = 0{;}
    ??

    I tried to find dummy functions in C++ on the internet but can not find anything applicable.

    Thanks

  19. #719
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,803
    dont use virtual and dont use = 0 for the class

    Code:
    bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2, uint32_t id3, uint32_t id4, uint32_t mask) {;} // empty function to satisfy base class

  20. #720
    Quote Originally Posted by tonton81 View Post
    dont use virtual and dont use = 0 for the class

    Code:
    bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2, uint32_t id3, uint32_t id4, uint32_t mask) {;} // empty function to satisfy base class

    I will 100% have to take your word for it as I can't find anything like the on the interweb....

    Thanks

    I dive it and let you know.

  21. #721
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h:314:18: error: 'virtual void FlexCAN_T4_Base::setBaudRate(uint32_t, FLEXCAN_RXTX)' cannot be overloaded
    virtual void setBaudRate(uint32_t baud = 1000000, FLEXCAN_RXTX listen_only = TX) = 0;
    ^
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h:308:18: error: with 'virtual void FlexCAN_T4_Base::setBaudRate(uint32_t, FLEXCAN_RXTX)'
    virtual void setBaudRate(uint32_t baud = 1000000, FLEXCAN_RXTX listen_only = TX) = 0;
    ^
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h:336:18: error: 'virtual void FlexCAN_T4_Base:nReceive(_MB_ptr)' cannot be overloaded
    virtual void onReceive(_MB_ptr handler) = 0; /* global callback function */
    ^
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h:331:15: error: with 'virtual void FlexCAN_T4_Base:nReceive(_MB_ptr)'
    virtual void onReceive(_MB_ptr handler) = 0; /* global callback function */
    ^
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h: In member function 'virtual void FlexCAN_T4_Base::reset()':
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h:315:38: error: 'softReset' was not declared in this scope
    virtual void reset() { softReset() = 0; } /* reset flexcan controller (needs register restore capabilities...) */
    ^
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h: In member function 'virtual void FlexCAN_T4_Base::disableFIFO()':
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h:318:48: error: invalid use of 'void'
    virtual void disableFIFO() { enableFIFO(0) = 0; }
    ^
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h: In member function 'virtual void FlexCAN_T4_Base::disableFIFOInterrupt()':
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h:320:66: error: invalid use of 'void'
    virtual void disableFIFOInterrupt() { enableFIFOInterrupt(0) = 0; }
    ^
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h: In member function 'virtual void FlexCAN_T4_Base::disableMBInterrupts()':
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h:329:64: error: invalid use of 'void'
    virtual void disableMBInterrupts() { enableMBInterrupts(0) = 0; }
    ^
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h: In member function 'bool FlexCAN_T4FD<_bus, _rxSize, _txSize>::setMBUserFilter(FLEXCAN_MAILBOX, uint32_t, uint32_t)':
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h:405:80: warning: no return statement in function returning non-void [-Wreturn-type]
    bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t mask){;}
    ^
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h: In member function 'bool FlexCAN_T4FD<_bus, _rxSize, _txSize>::setMBUserFilter(FLEXCAN_MAILBOX, uint32_t, uint32_t, uint32_t)':
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h:406:94: warning: no return statement in function returning non-void [-Wreturn-type]
    bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2, uint32_t mask){;}
    ^
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h: In member function 'bool FlexCAN_T4FD<_bus, _rxSize, _txSize>::setMBUserFilter(FLEXCAN_MAILBOX, uint32_t, uint32_t, uint32_t, uint32_t)':
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h:407:108: warning: no return statement in function returning non-void [-Wreturn-type]
    bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2, uint32_t id3, uint32_t mask){;}
    ^
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h: In member function 'bool FlexCAN_T4FD<_bus, _rxSize, _txSize>::setMBUserFilter(FLEXCAN_MAILBOX, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)':
    C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h:408:122: warning: no return statement in function returning non-void [-Wreturn-type]
    bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2, uint32_t id3, uint32_t id4, uint32_t mask){;} ^
    Code:
    static FlexCAN_T4_Base* myCAN[3] = { nullptr };
    FlexCAN_T4<CAN1, RX_SIZE_2, TX_SIZE_16> Can1;
    FlexCAN_T4<CAN2, RX_SIZE_2, TX_SIZE_16> Can2;
    FlexCAN_T4<CAN3, RX_SIZE_2, TX_SIZE_16> Can3;
    
    bool StartCAN()
    {
      myCAN[0] = &Can1;
      myCAN[1] = &Can2;
      myCAN[2] = &Can3;
      myCAN[0]->begin();
      myCAN[0]->disableFIFO();
      myCAN[0]->setMBFilter(REJECT_ALL);
      myCAN[0]->setBaudRate((uint16_t)(bus[0].BaudRate * 500));
      myCAN[0]->setMaxMB(NUM_TX_MAILBOXES + Num_Tot_RX_MB);
    Apparently it does not like a lot of these functions even setbaurdrate(

    Thanks

    Bruce

  22. #722
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,803
    virtual void disableFIFO() = 0; dont copy the bracket stuff
    Add only one at a time and compile to see if it is correct before pasting alot, too many errors to deal with after
    Last edited by tonton81; 05-31-2021 at 03:03 AM.

  23. #723
    What about the function overloading for baud rate?

    Also it does not seem to like C:\Users\bvernham\Dropbox (Isuzu North America)\Personal Backup\arduino-1.8.13\hardware\teensy\avr\libraries\FlexCAN_T4/FlexCAN_T4.h:408:122: warning: no return statement in function returning non-void [-Wreturn-type]
    bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2, uint32_t id3, uint32_t id4, uint32_t mask){;} ^

    Thanks

  24. #724
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,803
    thats just a warning you'll have to ignore unless you declare the function, function is blank, no return

  25. #725
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,803
    Code:
    class FlexCAN_T4_Base {
      public:
        virtual void flexcan_interrupt() = 0;
        virtual void setBaudRate(uint32_t baud = 1000000, FLEXCAN_RXTX listen_only = TX) = 0;
        virtual uint64_t events() = 0;
        virtual int write(const CANFD_message_t &msg) = 0;
        virtual int write(const CAN_message_t &msg) = 0;
        virtual bool isFD() = 0;
        virtual uint8_t getFirstTxBoxSize();
    };
    it's already there, did you duplicate it? Only reason it's there is because setClock uses it to reconfigure baudrate on a new controller clock switch

Posting Permissions

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