Teensy 3.2: Unable to get a successful CAN Bus read

Status
Not open for further replies.

moult

Member
I am trying to create a datalogging box for an OBD2 port on a car and I can not get any successful data reads to come through the FlexCAN library. I have stripped everything out of the design and am running a bare bones test setup and still can't get anything to come into the Teensy. I can successfully transmit data onto the bus, but can not pull it off. I am on my second transceiver chip and still no luck.I have also tried many example codes and written a sample myself. Any help that you could provide would be (greatly!) appreciated. I am nearing my wits end. Thank you!

Details:
Two Teensy 3.2s on a dedicateCAN Bus
Using MCP2562 Transceiver chip http://ww1.microchip.com/downloads/en/DeviceDoc/20005167C.pdf
Have a smt 120 Ohm resistor bridging the CAN H and L terminals at each transceiver
MCP2562 VDD pin wired to the Vsupply on each teensy
MCP2562 VIO pin wired to 3.3V on each Teensy
MCP2562 STNDBY pin pulled to ground (directly, no resistor)
Running the transmitting node (code below) powered by a USB port that is not host on a computer (charging port)
Running the receiving node via USB on my PC
Teensy pin 3 > MCP pin 1
Teensy pin 4 > MCP pin 4

Sending node code (example taken from here: http://webcache.googleusercontent.com/search?q=cache:http://rummanwaqar.com/can-bus-with-teensy-3-1/)

Code:
#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();
  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);
}

Receiving code:
Code:
#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();
  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("");
  }
}

Scope output:
Channel 1: Input to CAN TX on sending MCP2562
Channel 2: CAN HI
Channel 3: CAN LO
Channel 4: Pin 4 at receiving Teensy
NewFile1罚.png
 
I dont see your filters being set.
Some CAN Ids are 11bit, some are 29bit. For example, EXAMPLE, if your on a 29bit CAN network, by default, on another can shield with library, it's only set to receive 11bit.
Try your filters to accept all traffic from both 11 and 29bit IDs
 
if your trying this on your car, dont use any terminations on the CAN lines either. The car's CAN network is already terminated.
 
Thanks for the information. I will look more deeply into the masks and filters, but I was under the impression that the default was permissible to everything. Can you point me to any documentation on setting the filters? All of the examples I see seem to neglect it.

As I still can't get a packet in from the teensy<->teensy bus, I have a little more time before I connect it to the car.
 
skpang, Is your code using an older version of the Flexcan library? I though the parameter passed in the CAN.begin() function was a message mask and the speed was inputted when you defined the Flexcan element. Thanks.
 
i ended up not using the one on the T3.5, i needed 3 CANs so ended up going with 3 stacked shields of RX/TX CAN lines, 2 of which have different filtering, so 6 lines running to T3.5, and 3 lines to the CAN network, plus power, obviously. so 11 wires.
 
Got it! Skpang, I figured out I had that version of the library installed. So, I was calling the CAN with an initial mask when I thought that was the baudrate, thus not receiving the data.

Thanks for the help!
 
Status
Not open for further replies.
Back
Top