Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 13 of 13

Thread: FlexCAN library used on Teensy

  1. #1

    FlexCAN library used on Teensy

    I have been developing NMEA 2000 library and would like to add support for latest FlexCAN library. Which fork is used by Teensy project?

  2. #2
    The latest FlexCAN library coming with Teensy has some bugs, which I would like to fix. Some fixes are critical for using FlexCAN on NMEA2000 bus. I also made developed version of collin80 fork, which should still be compatible with current Teensy version.

    So how Teensy FlexCAN could be updated?

  3. #3
    Junior Member
    Join Date
    Jan 2017
    Posts
    17
    Quote Originally Posted by ttlappalainen View Post
    Which fork is used by Teensy project?
    The included version of the library in 1.37 seems to be the "9af9498 on 10 Jan" github version from collin80. Both FlexCAN.cpp have 749 lines and look the same. I haven't used a diff tool.

  4. #4
    So it has not been updated for a while and either collin80 has not merged or commented my pull request with improvements. Specially I wonder that newer version of FlexCAN uses interrupt handling for receiving as transmitting messages, but there is no locking mechanism for reading and writing buffers buffers outside of interrupt.

    So the question is still open - how FlexCAN could be updated for Teensy project?

  5. #5
    Junior Member
    Join Date
    Jan 2017
    Posts
    17
    Quote Originally Posted by ttlappalainen View Post
    Specially I wonder that newer version of FlexCAN uses interrupt handling for receiving as transmitting messages, but there is no locking mechanism for reading and writing buffers buffers outside of interrupt.
    I wondered about this, too, when doing my last CAN experiments with my small test setup. But it worked without errors for simple communication between two microcontrollers.

    Perhaps your request is better seen, if you post in in the Teensyduino Beta thread on top of the forum. Or post below under "Suggestions & Bug Reports".

    And Paul may not have recognized you as the man from this super long thread in the Arduino forum ...

  6. #6
    After I got new version working by fixing other issues (e.g. uninitialized variable before use) it also worked, but I had some message lost. After locking fix I have had 0 loss. Also current write may mix the order of send messages and right order is important specially with NMEA 2000 protocol fastpackets.

  7. #7
    Junior Member
    Join Date
    Jan 2017
    Posts
    17
    Quote Originally Posted by ttlappalainen View Post
    After locking fix I have had 0 loss. Also current write may mix the order of send messages and right order is important specially with NMEA 2000 protocol fastpackets.
    Ok, that's good to know. I've planned to move my ISO-TP work from mbed to Teensy.

    Are you going to make a second post or should I try it ?

  8. #8
    I added https://forum.pjrc.com/threads/45017...th-Teensyduino .

    Actually during write I realized, why there were not problem without locking with CAN. Since read/write indexes are handled seprately and processor makes incrementing in one clock (= can not be interrupted), it is OK. So on reading, user side changes read index and interrupt side write index. The problem rizes, when all frames has to be sent in order.

  9. #9
    By the way I had to add ISO-TP reception handling to NMEA 2000 library, since that was mandatory feature. It currently does not have ISO-TP sending.

  10. #10
    Junior Member
    Join Date
    Jan 2017
    Posts
    17
    Quote Originally Posted by ttlappalainen View Post
    By the way I had to add ISO-TP reception handling to NMEA 2000 library, since that was mandatory feature. It currently does not have ISO-TP sending.
    Ok, if I'll find some time I will look after this. The mbed version is currently based on mbed multithreading, so the first step is to decide about a redesign.

  11. #11
    Junior Member
    Join Date
    Feb 2018
    Location
    Germany
    Posts
    13
    So is still there a way to have ISO-TP support based on the FlexCAN lib for receiving e.g. a VIN via OBD request in Mode 0x09 to PID 0x02 ?

  12. #12
    Junior Member
    Join Date
    Jan 2017
    Posts
    17
    Well, I think simply receiving ISO-TP is a use case for FlexCAN's attachObj feature. A class acting as a state machine seems to be a good solution for this.

    Sending is much more complicated. It must follow the timing and wait requests coming from the receiving side. Using Arduino delay is not a good idea here, so threading or a timer lib is required.

  13. #13
    My original question is still open. Could FlexCan library provided with Teensyduino be my developed version. Now when people installs Teensyduino, it installs as default the version, which does not work right with NMEA2000. So to get things working, they have to manually remove FlexCan under "C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\FlexCA N"

Posting Permissions

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