Cant get CAN to work on Teensy 3.6 with the dual can board

Status
Not open for further replies.

slythy

Active member
I cant get any data from my system to the teensy. I currently have the CAN hooked up to my system (white HIGH, Blue Low, Orange is ground)

I am using CAN 1 on the dual CAN board. any reason why I'm not seeing anything?


the message i am sending over is ID 0x265 16bit long start bit 0, Little Endian (Intel) and its just a constant 12.345 to see if anything works.

Any ideas as to why this isn't working?


KNDpN0D.jpg


Code:
#include <IFCT.h>

void setup() {
  pinMode(2, OUTPUT); // for the transceiver enable pin
  Can1.setBaudRate(1000000);
  Can1.enableFIFO();
}

void loop() {
  CAN_message_t msg;
  if ( Can1.read(msg) ) canSniff(msg);
}

void canSniff(const CAN_message_t &msg) {
  Serial.print("MB "); Serial.print(msg.mb);
  Serial.print("  LEN: "); Serial.print(msg.len);
  Serial.print(" EXT: "); Serial.print(msg.flags.extended);
  Serial.print(" REMOTE: "); Serial.print(msg.rtr);
  Serial.print(" TS: "); Serial.print(msg.timestamp);
  Serial.print(" ID: "); Serial.print(msg.id, HEX);
  Serial.print(" Buffer: ");
  for ( uint8_t i = 0; i < msg.len; i++ ) {
    Serial.print(msg.buf[i], HEX); Serial.print(" ");
  } Serial.println();
}
 
Not sure what you have it attached to, but make sure on the other end you have low to low, high to high to high, gnd to gnd. Also make sure your baud rates match.
 
Its attached to a data logging system. All wires are connected correctly on the data system.

I changed it to CAN0 but still get nothing. I know things are on that CAN bus so its strange I get nothing.

Only thing I can think of is that I am using CAN 1 alt and dont know how to modify the code to make it use that one. Also with the tindy dual can bus pcb how do i pull the Rs* pin down so it stays in high powered mode?

Any help would be great.
 
Yea, the resistor is turned on in the data system and then there is a 120 ohm resistor on the fusion pcb. I tried to turn off the data systems resistor and still nothing.

Im wondering if there is something to do with the transever. pin 2 isnt attached to anything and i dont know if i need to make that another pin that goes to the receiver.
 
Use a scope and check the signals.

You should see data on CAN_L and CAN_H.

On the Teensy side you should see data on the CAN Rx pin.
 
there are 3 pins per chip side on teensy, 2 are for can lines, the other 1 is the transceiver enable pin. enable the pin and digitalwrite it ground
 
Instead of doing pinmod(2, OUTPUT); digitalWrite(2, LOW) you will probably need to do a:
Code:
 pinMode(35, OUTPUT); // for the transceiver enable pin
digitalWrite(35, LOW);

Looks like 2 problems you have to fix (1) use the correct enable pin and (2) then pull it low. Since you have it soldered on the T3.6 have to use 35 for CAN1 and 28 for CAN0. Schematic with the pinouts is here: https://www.tindie.com/products/Fusion/dual-can-bus-adapter-for-teensy-35-36/
 
Also tell the library to use the alt pins for Can0, which is normally 3 and 4 for default, you need to change them
 
Also tell the library to use the alt pins for Can0, which is normally 3 and 4 for default, you need to change them

I am looking at the IFCT Library and I am unsure of where to actually change whats been declared. I dont see anything in the IFCT.h that mentions the pin and there is some in the IFCT.cpp that mentions CORE_PIN3,29,30,33,34 but dont know what to change there as they seem to all be on if tx ==3 then tx==29 so it should fall over right?

Instead of doing pinmod(2, OUTPUT); digitalWrite(2, LOW) you will probably need to do a:

Code:
 pinMode(35, OUTPUT); // for the transceiver enable pin
digitalWrite(35, LOW);

Looks like 2 problems you have to fix (1) use the correct enable pin and (2) then pull it low. Since you have it soldered on the T3.6 have to use 35 for CAN1 and 28 for CAN0. Schematic with the pinouts is here: https://www.tindie.com/products/Fusion/dual-can-bus-adapter-for-teensy-35-36/

THanks, I will try that. I have switched back to CAN0 to try it but CAN1 may be a tad easier since I wont have to mod any of the library.



Thanks, guys I appreciate the help
 
@slythy

Try that enabling pin 35 like I recommended before changing to CAN0.

EDIT: its been awhile since I used IFCT but just checked:
Code:
CAN0.setTX(ALT);
CAN0.setRX(ALT);
I think is all that is need to use the alt pins for CAN0

Recommend looking at the Readme for the IFCT library and the datasheet for the dual can board you have. It helps in understanding the hook ups and what is available.
 
Last edited:
Here is my code as it sits, My Serial monitor is still blank. I get 120ohms across the lines when i beep them out. I have a decent amount coming across that bus right now so I cant believe its not seeing anything.

is there a 0x0XX-0x999 range limit or something?


Code:
#include <IFCT.h>

void setup() {

pinMode(28, OUTPUT); // for the transceiver enable pin
digitalWrite(28,LOW);
  
Can0.setTX(ALT);
Can0.setRX(ALT);
Can0.setBaudRate(1000000);
Can0.enableFIFO();

}

void loop() {
  CAN_message_t msg;
  if ( Can0.read(msg) ) canSniff(msg);
  
}

void canSniff(const CAN_message_t &msg) {
  Serial.print("MB "); Serial.print(msg.mb);
  Serial.print("  LEN: "); Serial.print(msg.len);
  Serial.print(" EXT: "); Serial.print(msg.flags.extended);
  Serial.print(" REMOTE: "); Serial.print(msg.rtr);
  Serial.print(" TS: "); Serial.print(msg.timestamp);
  Serial.print(" ID: "); Serial.print(msg.id, HEX);
  Serial.print(" Buffer: ");
  for ( uint8_t i = 0; i < msg.len; i++ ) {
    Serial.print(msg.buf[i], HEX); Serial.print(" ");
  } Serial.println();
}
 
Sounds like at this point you have a baud rate mismatch. Whats the baud rate coming from the data system? They have to match. Are you using CAN 2.0 or CAN-FD on your data side? Assuming its CAN 2.0. Is there a transceiver on the data side?
 
your sketch looks alright, check the baudrate is correct and dont cross the canh/canl lines, must be canh to canh, canl to canl, and common ground, either from teensy or the ground pin of the shield
 
Ok progress! I have 8 CAN busses on my data system and I read the data sheet wrong. Now i get some messages. Is the buffer the start of each of the 8 messages? I notice when I shift it around that C moves.

So my data getting sent over is 16bit long message. the entire packet is 64 bits. How do I actually see the data that is read? I need to be able to save what it reads as a value. So that 12.345 will be a sensor sent over CAN and I need to do math on that to direct the outputs. Im going to have like 10 sensor inputs (which is why I'm trying CAN over analog in).

Any idea?

t1SyBkY.png
 
yes buffer is the data field output, 8 bytes, you can access the bytes from the canSniff function

16 bits is 2 data bytes

(uint16_t)(msg.data[0] << 8) | msg.data[1];
should join 2 bytes to get the 16 bit result you want
 
Last edited:

Hey I got my project working and can get it to read CAN messages all day! thanks for that.

Now I have a question of how i can send a can message using that code.

Is it like Can0.write(msg)? how do I tell it which bit or anything like that? Do you have a simple example?

thanks.
 
Status
Not open for further replies.
Back
Top