-
Notifications
You must be signed in to change notification settings - Fork 0
Teensy CAN
For CAN software, we will be using the acan_t4 library. This is a CAN library for Teensy 4.Xs. Download it as a zip file from this link. There is also a long pdf of documentation (read this for a general understanding of the code). Next, open up the Teensyduino IDE and go to sketch, then include library, and add .zip library.
In terms of wiring, we will use the CAN nmodule. The Teensy has 2 CRX and CTX pins that are for CAN communication. Check the laminated sheet for information on Pin configuration but for reference, CRX1 = pin 23, CTX1 = pin 22, CRX2 = pin 0, and CTX2 = pin 1. When connecting to the CAN module, you will need to connect 3.3 V and GND to it, then connect RX from the Teensy to RX on the module and same thing for TX.
No external wiring needed for this test. All the messages are sent internally. Click Files, then Examples, then acan_t4, then LoopbackDemoCAN1. Or you can copy the code from the github (same file name). Run the code and in Serial monitor, make sure it prints both Sent AND Received. Right now, LoopBackMode and SelfReceptionMode is set to true, so the message is sent and received internally.
Make sure that the following are set to true: ''' settings.mLoopBackMode = true ; settings.mSelfReceptionMode = true ; '''
Now we want to test communication from between 2 CAN modules. In the code, set LoopBackMode and SelfReceptionMode to false to stop sending the message internally. The messages will now to through the TX pin and be received at RX. Also, add the line const uint32_t errorCode2 = ACAN_T4::can2.begin (settings); to initialize the 2nd CAN transceiver (under errorCode). At the bottom in the loop, change if (ACAN_T4::can1.receive (message)) to if (ACAN_T4::can2.receive (message)). Since we are using 2 CAN modules, configure it as described above for both modules (using both CRX2/CTX2 and CRX1/CTX1). Then wire the CANHs of both modules together and the CANLs of both modules together.
Run the code and make sure Sent and Received both appear in the serial monitor. Next unplug the connection b/t CAN1 and CAN2 (either CANH or CANL) and make sure that only Sent appears in the Serial monitor after that.
Here we are sending/receiving through 1 module so disconnect CAN2. From the Arduino, there should be a CAN shield plugged into it with 2 connectors with CANH and CANL. Screw in 2 wires and connect CANH to CANH of the module and same thing with CANL. Use the code in CAN_Test.ino and for the Teensy, you can use the same code as above, but just with one CAN module (so delete the code for can2). Make sure to comment out sending code if receiving and vice versa.
Same thing as with the Arduino, just connect CANH and CANL to the CANH and CANL of the VCU. Refer to ______________ for the code for the VCU.