Hello,
I am trying to communicate to a motor controller via CAN bus on a Teensy 3.6 with a Waveshare CAN transceiver. I am using an oscilloscope to analyze the communication with CAN High and Low. The Teensy is using the FlexCan library to test the communication. From the Teensy perspective, the oscilloscope shows random bursts of data which tops at 25 mV. From the motor controller perspective, the oscilloscope shows continuous bursts of data topping at 230 mV.
When both the motor controller and transceiver are connected, the code that is being used displays nothing because the CAN0.available() is false.
I am using a Waveshare transiever: https://www.amazon.com/SN65HVD230-CAN-Board-Communication-Development/dp/B00KM6XMXO
Here is the code I am using:
The motor controller being used is an RMS p100x. Here is a link to its CAN protocol https://app.box.com/s/4fb49r9p6lzfz4uwcb5izkxpcwh768vc
Should the difference I am seeing on the oscilloscope be that dramatic?
Any idea why CAN0.available() is false?
Any help with this would be much appreciated.
I am trying to communicate to a motor controller via CAN bus on a Teensy 3.6 with a Waveshare CAN transceiver. I am using an oscilloscope to analyze the communication with CAN High and Low. The Teensy is using the FlexCan library to test the communication. From the Teensy perspective, the oscilloscope shows random bursts of data which tops at 25 mV. From the motor controller perspective, the oscilloscope shows continuous bursts of data topping at 230 mV.
When both the motor controller and transceiver are connected, the code that is being used displays nothing because the CAN0.available() is false.
I am using a Waveshare transiever: https://www.amazon.com/SN65HVD230-CAN-Board-Communication-Development/dp/B00KM6XMXO
Here is the code I am using:
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
msg.ext = 0;
msg.id = 0x0A0;
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)
{
delay(22);
CAN_message_t inMsg;
if(Can0.available()){
Serial.println("Here reading");
Can0.read(inMsg);
Serial.print("[ECHO]CAN bus 0: "); hexDump(8, inMsg.buf);
}
msg.buf[0]++;
Can0.write(msg);
msg.buf[0]++;
Can0.write(msg);
msg.buf[0]++;
Can0.write(msg);
msg.buf[0]++;
Can0.write(msg);
msg.buf[0]++;
Can0.write(msg);
//delay(20);
}
The motor controller being used is an RMS p100x. Here is a link to its CAN protocol https://app.box.com/s/4fb49r9p6lzfz4uwcb5izkxpcwh768vc
Should the difference I am seeing on the oscilloscope be that dramatic?
Any idea why CAN0.available() is false?
Any help with this would be much appreciated.