Okay, thanks.
Here is the code, it is the same for both Teensy s, but I also tried running it with no code uploaded on the 2nd teensy.
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 Can1(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)
{
Can1.begin(1000000);
pinMode(led, OUTPUT);
pinMode(32, OUTPUT);
delay(1000);
Serial.println(F("Hello Teensy 3.1 CAN Test."));
sysTimer.reset();
}
// -------------------------------------------------------------
void loop(void)
{
digitalWrite(32, HIGH);
digitalWrite(led, 1);
// 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 bit
if ( !rxTimer ) {
while ( Can1.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] = '1';
}*/
msg.buf[0] = '0';
msg.buf[1] = '0';
msg.buf[2] = '0';
msg.buf[3] = '0';
msg.buf[4] = '0';
msg.buf[5] = '0';
msg.buf[6] = '0';
msg.buf[7] = '0';
// send 6 at a time to force tx buffering
txCount = 6;
digitalWrite(led, 1);
Serial.println("sending...");
while ( txCount-- ) {
Can1.write(msg);
msg.buf[0]++;
}
digitalWrite(led, 0);
// time delay to force some rx data queue use
rxTimer = 3;//milliseconds
}
}
Other codes that I tried:
Transmitter:
Code:
// -------------------------------------------------------------
// CANtest for Teensy 3.6 dual CAN bus
// by Collin Kidder, Based on CANTest by Pawelsky (based on CANtest by teachop)
//
// Both buses are left at default 250k speed and the second bus sends frames to the first
// to do this properly you should have the two buses linked together. This sketch
// also assumes that you need to set enable pins active. Comment out if not using
// enable pins or set them to your correct pins.
//
// This sketch tests both buses as well as interrupt driven Rx and Tx. There are only
// two Tx buffers by default so sending 5 at a time forces the interrupt driven system
// to buffer the final three and send them via interrupts. All the while all Rx frames
// are internally saved to a software buffer by the interrupt handler.
//
#include <FlexCAN.h>
#ifndef __MK66FX1M0__
#error "Teensy 3.6 with dual CAN bus is required to run this example"
#endif
static CAN_message_t msg;
static uint8_t hex[17] = "0123456789abcdef";
// -------------------------------------------------------------
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)
{
delay(1000);
Serial.println(F("Hello Teensy 3.6 dual CAN Test."));
Can0.begin();
Can1.begin();
//if using enable pins on a transceiver they need to be set on
pinMode(13, OUTPUT);
pinMode(35, OUTPUT);
digitalWrite(13, HIGH);
digitalWrite(35, HIGH);
msg.ext = 0;
msg.id = 0x100;
msg.len = 8;
msg.buf[0] = 10;
msg.buf[1] = 20;
msg.buf[2] = 0;
msg.buf[3] = 100;
msg.buf[4] = 128;
msg.buf[5] = 64;
msg.buf[6] = 32;
msg.buf[7] = 16;
}
// -------------------------------------------------------------
void loop(void)
{
msg.buf[0]++;
Can1.write(msg);
msg.buf[0]++;
Can1.write(msg);
msg.buf[0]++;
Can1.write(msg);
msg.buf[0]++;
Can1.write(msg);
msg.buf[0]++;
Can1.write(msg);
delay(20);
}
Receiver:
Code:
// -------------------------------------------------------------
// CANtest for Teensy 3.6 dual CAN bus
// by Collin Kidder, Based on CANTest by Pawelsky (based on CANtest by teachop)
//
// Both buses are left at default 250k speed and the second bus sends frames to the first
// to do this properly you should have the two buses linked together. This sketch
// also assumes that you need to set enable pins active. Comment out if not using
// enable pins or set them to your correct pins.
//
// This sketch tests both buses as well as interrupt driven Rx and Tx. There are only
// two Tx buffers by default so sending 5 at a time forces the interrupt driven system
// to buffer the final three and send them via interrupts. All the while all Rx frames
// are internally saved to a software buffer by the interrupt handler.
//
#include <FlexCAN.h>
#ifndef __MK66FX1M0__
#error "Teensy 3.6 with dual CAN bus is required to run this example"
#endif
static CAN_message_t msg;
static uint8_t hex[17] = "0123456789abcdef";
// -------------------------------------------------------------
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)
{
delay(1000);
Serial.println(F("Hello Teensy 3.6 dual CAN Test."));
Can0.begin();
Can1.begin();
//if using enable pins on a transceiver they need to be set on
pinMode(2, OUTPUT);
pinMode(35, OUTPUT);
digitalWrite(2, HIGH);
digitalWrite(35, HIGH);
}
// -------------------------------------------------------------
void loop(void)
{
CAN_message_t inMsg;
while (Can1.available())
{
Can1.read(inMsg);
Serial.print("CAN bus 0: "); hexDump(8, inMsg.buf);
}
}
using the last codes no signal was measured on the canH/canL wires
EDIT: an additional note: if in the first code the can1.write() function is commented for one teensy so that it only reads, the signal is gone for both teensys in the Tx pin