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

Thread: Not able to read CANbus data with Teensy 3.2 uController using the Flexcan library

  1. #1
    Junior Member
    Join Date
    Oct 2018
    Posts
    2

    Not able to read CANbus data with Teensy 3.2 uController using the Flexcan library

    We are converting a oldtimer Jaguar XJ-6 from 1988. It will be from the outside a classical jaguar expression but from the inside a electrical powered system. But to keep the originalnal dashboard cluster I need to develop a CANbus interface.

    I already managed to work with the arduino due and the dueCAN library from Collin Kidder (https://github.com/collin80). Credits for that!

    But now I want it to work with the Teensy 3.2 microcontroller. I am able to Send Canbus frames but for some reason I Cannot read any data. I have tried every FlexCAN library version availible. But nothing works. I am almost 100% sure the hardware connection is correct. My guess is that ther is a weird software isseu. Any Help or tips that can provide would be appreciated.

    Some detaills:
    a Teensy 3.2 microcontroller on a working CANbus line with a MCP2551 CANbus transeiver. On the same CAN bus line an arduino due with the GVRET SavvyCAN software to monitor the CANbus frames.
    Flexcan version I used:
    https://github.com/teachop/FlexCAN_Library
    https://github.com/pawelsky/FlexCAN_Library
    https://github.com/collin80/FlexCAN_Library

    The working code I used to transmit :

    #include <FlexCAN.h>
    #include <kinetis_flexcan.h>

    int led = 13;
    // create CAN object
    FlexCAN CANTransmitter(500000);
    static CAN_message_t msg;

    void setup() {
    // init CAN bus
    CANTransmitter.begin(500000);
    pinMode(led, OUTPUT);
    delay(1000);
    Serial.println("CAN Transmitter Initialized");
    }

    void loop() {
    Serial.print("Sending: ");
    msg.id = 0x222;
    msg.len = 2;
    for(int i=0; i<msg.len; i++) {
    msg.buf[i] = '0' + i;
    Serial.print(msg.buf[i]); Serial.print(" ");
    }
    Serial.println("");
    CANTransmitter.write(msg);
    digitalWrite(led, !digitalRead(led));
    delay(500);
    }

    The code to recieve ( that is not working ):

    #include <FlexCAN.h>
    #include <kinetis_flexcan.h>

    int led = 13;
    // create CAN object
    FlexCAN CANReceiver(500000);
    static CAN_message_t msg;

    void setup() {
    // init CAN bus
    CANReceiver.begin(500000);
    pinMode(led, OUTPUT);
    delay(1000);
    Serial.println("CAN Receiver Initialized");
    }

    void loop() {
    while( CANReceiver.read(msg)) {
    // toggle LEDs
    digitalWrite(led, !digitalRead(led));
    Serial.print("Receiving: ");
    for(int i=0; i<msg.len; i++) {
    Serial.print(msg.buf[i]); Serial.print(" ");
    }
    Serial.println("");
    }
    }


    NOTE: I used some information from an other topic. But I think there is an other problem.
    (https://forum.pjrc.com/threads/41899...l-CAN-Bus-read)

    already thank you all for the support!

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,743
    you havnít tried all libraries. there are multiple forks of those libraries some work some donít. i believe the working one you need to search the forums for nmea2000 and youíll find it. there is also a new one called IFCT which has a very easy interface for the user. The examples demonstrate itís usage and simplicity, however this library is tailored specifically for teensy 3.x series (so 3.2 as well), you only need a transceiver to use the one built in your 3.2

    Tony

  3. #3
    Junior Member
    Join Date
    Oct 2018
    Posts
    2
    Thanks you Tony! it worked at ones!

Posting Permissions

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