CAN Bus Communication Between Two STM32 Boards (Node-to-Node)
This project demonstrates CAN communication between two STM32 MCUs using the HAL library.
Node 1 periodically sends and requests data, while Node 2 responds and blinks LEDs based on received commands.
The setup closely follows the concept shown below, adapted to different hardware and extended with additional debugging tools.
| Node | Board | Role |
|---|---|---|
| Node 1 | NUCLEO-L476RG | CAN Master β sends and request data |
| Node 2 | STM32F4-Discovery | CAN Slave β responds, blinks LEDs |
- CAN initialization with HAL library
- Node 1 sends LED number every 1 s via Data Frame
- Node 2 toggles the corresponding LED on reception
- Node 1 sends Remote Frame every 4 s requesting 2 bytes of data
- Node 2 responds to Remote Frame with Data Frame
- Fully interrupt-driven code (TX/RX callbacks)
- UART debug output for monitoring CAN activity
- Optional logic analyzer capture to verify timing
| Frame Type | CAN ID | DLC | Direction | Payload Example | Purpose |
|---|---|---|---|---|---|
| LED Command | 0x65D |
1 | Node1 β Node2 | 02 |
Turns on LED #2 on Node2 |
| Remote Request | 0x651 |
2 (RTR) | Node1 β Node2 | β | Asks for 2 bytes of data |
| Remote Reply | 0x651 |
2 | Node2 β Node1 | 01 2C |
Replies with 16-bit value (MSB first) |
| Signal | Node 1 Pin | Node 2 Pin |
|---|---|---|
| CAN_RX | PA11 | PB8 |
| CAN_TX | PA12 | PB9 |
| GND | GND | GND |
Below is the actual setup used for this project:
