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

Thread: Teensy 3.6 - FlexCAN - Listen and respond

  1. #1
    Junior Member
    Join Date
    Sep 2015
    Posts
    14

    Teensy 3.6 - FlexCAN - Listen and respond

    Hi!

    A few weeks ago I posted a question in the project guidance forum but never received any feedback. Thought it might be the wrong place so I give it a try here instead.


    My goal is rather simple. I want the Teensy to respond to a frame when its detected on the bus. But I don't know how to implement it with the help of the FlexCAN library examples. I have a Teensy 3.6 and a CAN transceiver module SN65HVD230.


    Pseudo code
    Code:
    loop() {
    Listen on CAN bus for certain frame.
    If frame == "t568101" detected..
    then 
    send on CAN bus "t5653001511" in decimal format.
    }

    Have anyone done something similar and can post an example snipped of code?


    Code:
    #include <FlexCAN.h>
    
    
    void setup() {
    delay(1000);
    Serial.println(F("Starting up..."));
    Can0.begin(500000);   
    }
    
    void loop() {
    }

    Regards
    Tobias

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,915
    Its definately possible to do, a received frame ID would update the msg.id with the CAN ID of the frame.

    But what do you mean frame id is t568101?, that is not valid, are you looking at the data field?

  3. #3
    Junior Member
    Join Date
    Sep 2015
    Posts
    14
    Thank you for taking time to look at my project tonton.

    The "t568101” is a frame as I have read it on my CANbus with a canbus sniffer device. According to my research in translates into:
    t = transmit
    568 = frame hex ID
    101 = payload in hex.

  4. #4
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,915
    irregardless, you will have no issue identifying that frame when you see it, 568 will be populating the msg.id variable and your payload will appear in msg.buf[x];

    sorry I didn’t catch your last post I would have definately helped you out

    You can try out my IFCT library, there are simple examples included with it

  5. #5
    Junior Member
    Join Date
    Sep 2015
    Posts
    14
    Thank you. Looking at your library now.

    So what I need to do is create an IF statement on the content of msg.id variable and msg.buf[x] compared to the ID and string I'm looking for?

  6. #6
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,915
    pretty much yeah

    but start it easy first, let it show what it sees on the serial monitor when the transmissions occur, the rest will come to you easily

  7. #7
    Junior Member
    Join Date
    Sep 2015
    Posts
    14
    Thank you. I will give it a go and get back here. =)

Posting Permissions

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