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

Thread: CAN Project Weird Issue

  1. #1
    Junior Member
    Join Date
    Jul 2017
    Posts
    4

    CAN Project Weird Issue

    Hi,

    This could be something daft, it likely is.. I'm fairly new to this stuff.

    I have a car ECU powered by my bench PSU, this provides a CAN stream at 1mbd which I am successfully receiving via a Waveshare SN65HVD230 (Chinese copy, I have an original Waveshare product en-route from Amazon).

    My project is wired as follows

    SN65 on the left, Teensy 3.2 on the right

    TX-> Pin 3 (Purple Wire)
    RX-> Pin 4 (Blue Wire)
    GND-> GND (Black to Brown Wire)
    3.3v-> 3.3v (Green to Red Wire)

    The teensy powered from USB.

    The CAN stream I'm receiving sends a total of 8 data blocks with ID's: 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007. I'm mostly receiving the first 2000 block, and every now and again, the second 2001 block. Until I physically touch the RX and TX wires from the Transveiver to the Teensy, and then I get a proper data stream including all of the above data blocks.

    I'm puzzled as to why me taking a hold of the wires makes this work, but when I'm not touching the wires it seems to repeat?

    Hopefully someone has a suggestion.

    Thanks

    Here's a photo of my project



    Here's the sketch I'm using

    Code:
    #include <FlexCAN.h>
    #include <kinetis_flexcan.h>
    
    int led = 13;
    FlexCAN CANbus(1000000);
    static CAN_message_t rxmsg;
    static uint8_t hex[17] = "0123456789abcdef";
    
    
    void setup() {
    
      Serial.begin(9600);
      while (!Serial) ; // wait for Arduino Serial Monitor
      Serial.println(F("Teensy 3.2 CAN Test"));
    
      CANbus.begin();
      pinMode(led, OUTPUT);
      digitalWrite(led, 1);
    
      delay(1000);
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      while (CANbus.read(rxmsg)) {
        // Light off to indicate FIFO is not being polled
        digitalWrite(led, 0);
    
        // Construct String
        String text = "ID: 0x";
        text = String(text + String(rxmsg.id, HEX));
        text = String(text + " DLC: ");
        text = String(text + String(rxmsg.len, HEX));
    
        // check if DLC is > 0
        if (rxmsg.len >= 1) {
          text = String(text + " DATA: ");
        }
    
        // construct string for available bytes
        for (int idx = 0; idx < rxmsg.len; ++idx) {
          text = String(text + String(rxmsg.buf[idx], HEX));
          text = String(text + " ");
        }
    
        // print result
        Serial.println(text);
    
        // LED Back on to indicate watching FIFO
        digitalWrite(led, 1);
        
      }
    
    }

  2. #2
    Junior Member
    Join Date
    Jul 2017
    Posts
    4
    I have a 5v step down board which I've used to power the entire project meaning everything is ground to a single source now.

    I am still only receiving the first Data block (2000) but now, me touching the TX and RX wires doesn't cause more data blocks to be received.

    Colour me confused!

  3. #3
    Is there a 120R terminator resistor on board? Is it closed ? If not closed try and close it.

  4. #4
    Junior Member
    Join Date
    Jul 2017
    Posts
    4
    Thanks for the reply.

    My Waveshare CAN Transceiver arrived in the post today, and I can confirm that this has fixed my problem.

Posting Permissions

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