Hi,
I am trying to use a Teensy 3.5 with a TI SN65HVD230 3.3V CAN transceiver for a Senior Design project at school.
I can not for the life of me get the regular, or any of the other sketches I've seen on the internet to work.
The wiring is straight from the breakout board to the pins on the teensy, no pull up or pull down resistors.
Here's what I have done:
It seems like the receive portion is what I am having trouble with and again, I cannot figure out what's going on.
I have tried a number of different examples, but ill post the CANTest sketch from the FlexCAN library
I am trying to use a Teensy 3.5 with a TI SN65HVD230 3.3V CAN transceiver for a Senior Design project at school.
I can not for the life of me get the regular, or any of the other sketches I've seen on the internet to work.
The wiring is straight from the breakout board to the pins on the teensy, no pull up or pull down resistors.
Here's what I have done:
- I have verified with an oscilloscope that the transceivers are doing their job. The voltages follow the correct path and deviate away and towards each other like they should.
- I have verified that the RX and TX pins are correctly aligned, and that the signals are making their way to the correct pins on the teensy
- I have verified that the sending portion of all the sketches I have tried work, I can see the activity on the bus
- I have verified that the pins are still operational on each teensy by checking whether or not they can register a high or low digital state.
- I have tested the bus resistance and it is sitting at 64ohms, within spec according to a troubleshooting guide i found.
It seems like the receive portion is what I am having trouble with and again, I cannot figure out what's going on.
- I am using the pawelsky FlexCAN fork.
- I am using the latest Teensyduino from the site.
- I am using Arduino 1.8.8
I have tried a number of different examples, but ill post the CANTest sketch from the FlexCAN library
Code:
// -------------------------------------------------------------
// CANtest for Teensy 3.1
// by teachop
//
// This test is talking to a single other echo-node on the bus.
// 6 frames are transmitted and rx frames are counted.
// Tx and rx are done in a way to force some driver buffering.
// Serial is used to print the ongoing status.
//
#include <Metro.h>
#include <FlexCAN.h>
Metro sysTimer = Metro(1);// milliseconds
int led = 13;
FlexCAN CANbus(500000);
static CAN_message_t msg,rxmsg;
static uint8_t hex[17] = "0123456789abcdef";
int txCount,rxCount;
unsigned int txTimer,rxTimer;
// -------------------------------------------------------------
static void hexDump(uint8_t dumpLen, uint8_t *bytePtr)
{
uint8_t working;
while( dumpLen-- ) {
working = *bytePtr++;
Serial.write( hex[ working>>4 ] );
Serial.write( hex[ working&15 ] );
}
Serial.write('\r');
Serial.write('\n');
}
// -------------------------------------------------------------
void setup(void)
{
CANbus.begin();
pinMode(led, OUTPUT);
digitalWrite(led, 1);
delay(1000);
Serial.println(F("Hello Teensy 3.1 CAN Test."));
sysTimer.reset();
}
// -------------------------------------------------------------
void loop(void)
{
// service software timers based on Metro tick
if ( sysTimer.check() ) {
if ( txTimer ) {
--txTimer;
}
if ( rxTimer ) {
--rxTimer;
}
}
// if not time-delayed, read CAN messages and print 1st byte
if ( !rxTimer ) {
while ( CANbus.read(rxmsg) ) {
//hexDump( sizeof(rxmsg), (uint8_t *)&rxmsg );
Serial.write(rxmsg.buf[0]);
rxCount++;
}
}
// insert a time delay between transmissions
if ( !txTimer ) {
// if frames were received, print the count
if ( rxCount ) {
Serial.write('=');
Serial.print(rxCount);
rxCount = 0;
}
txTimer = 100;//milliseconds
msg.len = 8;
msg.id = 0x222;
for( int idx=0; idx<8; ++idx ) {
msg.buf[idx] = '0'+idx;
}
// send 6 at a time to force tx buffering
txCount = 6;
digitalWrite(led, 1);
Serial.println(".");
while ( txCount-- ) {
CANbus.write(msg);
msg.buf[0]++;
}
digitalWrite(led, 0);
// time delay to force some rx data queue use
rxTimer = 3;//milliseconds
}
}