Feather STM32F405 Express & External Transceiver
The Feather STM32F405 has a built in CAN peripheral, but it requires an external transceiver.
Wiring is reasonably straightforward, but you need to take note of the following:
- Whether the transceiver needs 5V (more common) or 3.3V (less common) on its power input pin. On my transceiver, 5V is required, and comes from the USB pin on the Feather
- Whether the TX and RX pins refer to the microcontroller's point of view or the transceiver point of view. On my transceiver, TX and RX refer to the transceiver's point of view.
- Whether there is an enable pin, and whether to set it
True
orFalse
On an STM32F405 Feather, the pin marked D9 is the CAN TX (data FROM feather INTO transceiver); the pin marked D10 is the CAN RX (data INTO Feather FROM transceiver) pin.
Here's how to wire up two STM32 Feathers:
Feather 1 ↔ Transceiver 1 ↔ Transceiver 2 ↔ Feather 2
After reviewing the CAN breakout board I used, I made the following connections between each Feather and its Transceiver:
- Feather USB to Transceiver VCC
- Feather D9 to Transceiver TX
- Feather D10 to Transceiver RX
- Feather GND to Transceiver GND
Make the following connections between the two transceivers:
- H to H
- L to L
Finally, we need a common GND between the two nodes on the network. If they are not already sharing a GND (for instance, plugged into the same USB hub or USB power bank, or connecting to a GND rail on a breadboard),
- either connect GND from Feather 1 to Feather 2
- or connect GND from Transceiver 1 to Transceiver 2
ESP32S2 Metro & External Transceiver
The ESP32S2 has a built in CAN-compatible peripheral (called TWAI in the documentation from Espressif). You can choose any two pins to act as the RX and TX pins, but when it comes to the sample code you'll need to change board.CAN_RX
and board.CAN_TX
to the pins you wired up. I arbitrarily chose IO05
and IO06
.
Wiring is reasonably straightforward, but you need to take note of the following:
- Whether the transceiver needs 5V (more common) or 3.3V (less common) on its power input pin. On my transceiver, 5V is required, and comes from the VHI pin on the Metro
- Whether the TX and RX pins refer to the microcontroller's point of view or the transceiver's point of view. On my transceiver, TX and RX refer to the microcontroller's point of view.
- Whether there is an enable pin, and whether to set it
True
orFalse
Here's how to wire up two Metro ESP32S2 Express board:
Metro 1 ↔ Transceiver 1 ↔ Transceiver 2 ↔ Metro 2
In the code samples, change the setup line for the CAN object according to the pins you chose, e.g.,:
can = canio.CAN(rx=board.IO6, tx=board.IO5, baudrate=250_000, auto_restart=True)
After reviewing the CAN breakout board I used, I made the following connections between each Feather and its Transceiver:
- Metro VHI to Transceiver VCC
- Metro IO5 to Transceiver TX
- Metro IO6 to Transceiver RX
- Metro GND to Transceiver GND
Make the following connections between the two transceivers:
- H to H
- L to L
Finally, we need a common GND between the two nodes on the network. If they are not already sharing a GND (for instance, plugged into the same USB hub or USB power bank, or connecting to a GND rail on a breadboard),
- either connect GND from Metro 1 to Metro 2
- or connect GND from Transceiver 1 to Transceiver 2
Because the transceiver is included, wiring a CAN bus is simple:
- Connect H to H
- Connect L to L
- Connect GND to GND (other ways of providing a common GND are also acceptable, such as powering both devices from the same computer or USB power bank)
In the case of the Feather M4 CAN, just insert wires into each screw terminal and then tighten the screw.
Make sure that H goes to H and L to L; Otherwise, the devices will not be able to communicate.
Mix and Match
Want to make a network out of different boards? Knock yourself out. Just wire each side as above, then connect the H, L, and GND wires between the nodes in the network. For example, you could wire
Metro ESP32S2 ↔ Transceiver 1 ↔ Transceiver 2 ↔ Feather STM32F405
or
Feather STM32F405 ↔ Transceiver ↔ Feather CAN
In principle, you can put more than two nodes on a network by connecting all the H wires together and all the L wires together. However, you also need to understand and may need to modify the "termination resistance" of the bus—that's beyond the scope of this guide (and indeed your humble author's experience)
Text editor powered by tinymce.