PaulS
Well-known member
Been trying to read out a CAN-based touch encoder but I'm stuck at just receiving the CAN bus data.
Here is the setup:
Parts here: Teensy 3.2, Waveshare CAN transceiver [powered by 3V3] and a Grayhill Touch Encoder [powered by 5V]. Datasheet of the encoder is here.
The encoder spits out CAN data at 250kbps and uses the extended frame format with 8 data bytes.
I hooked up the logic analyzer to the CAN RX pin of the transceiver board and this is output:
The identifier matches the datasheet and as far as I can tell the CAN message seems valid. Also the signal on pin 4 of the Teensy looks OK on the oscilloscope.
Now I'm trying to get the Teensy read this CAN bus data. I'm using the latest copy of the FlexCAN library. Copied that library into Arduino\Libraries and removed the one that came with Teensyduino. Using Arduino 1.8.13, Teensyduino 1.53.
Here is my basic code that compiles without error or warning:
But no CAN data is shown in the serial monitor after the CAN Receiver Initialized line.
I also tried the FlexCAN_T4 library and a few other CAN libraries on GitHub but I just don't seem to be able to read the CAN data. I even tried a little sketch using digitalRead to check whether pin 4 was perhaps dead but it's OK. Also the 5V and 3V3 are OK on the Teensy and transceiver board.
Any idea what I'm doing wrong here? I'm out of ideas what to try next.
Thanks,
Paul
Here is the setup:
Parts here: Teensy 3.2, Waveshare CAN transceiver [powered by 3V3] and a Grayhill Touch Encoder [powered by 5V]. Datasheet of the encoder is here.
The encoder spits out CAN data at 250kbps and uses the extended frame format with 8 data bytes.
I hooked up the logic analyzer to the CAN RX pin of the transceiver board and this is output:
The identifier matches the datasheet and as far as I can tell the CAN message seems valid. Also the signal on pin 4 of the Teensy looks OK on the oscilloscope.
Now I'm trying to get the Teensy read this CAN bus data. I'm using the latest copy of the FlexCAN library. Copied that library into Arduino\Libraries and removed the one that came with Teensyduino. Using Arduino 1.8.13, Teensyduino 1.53.
Here is my basic code that compiles without error or warning:
Code:
#include <FlexCAN.h>
static CAN_message_t msg;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
while (!Serial);
Can0.begin(250000); // init CAN bus
Serial.println("CAN Receiver Initialized");
}
void loop() {
if (Can0.available()) {
Can0.read(msg);
digitalToggle(LED_BUILTIN);
Serial.print("Receiving: ");
for (int i = 0; i < msg.len; i++) {
Serial.print(msg.buf[i]); Serial.print(" ");
}
Serial.println("");
}
}
But no CAN data is shown in the serial monitor after the CAN Receiver Initialized line.
I also tried the FlexCAN_T4 library and a few other CAN libraries on GitHub but I just don't seem to be able to read the CAN data. I even tried a little sketch using digitalRead to check whether pin 4 was perhaps dead but it's OK. Also the 5V and 3V3 are OK on the Teensy and transceiver board.
Any idea what I'm doing wrong here? I'm out of ideas what to try next.
Thanks,
Paul