Skip to content

CAN Transceiver MCP2515 (STM32) - MCP2515 + TJA1050 CAN Bus Module

Overview

The MCP2515 + TJA1050 CAN bus module connects a microcontroller to a CAN network, the bus used in vehicles and industrial equipment.

The module has two chips:

  • Microchip MCP2515: CAN controller. The MCU controls it over SPI.
  • NXP TJA1050: CAN transceiver. It drives the two-wire CAN bus (CANH/CANL).

The STM32F411 has no CAN peripheral, so it needs an external controller like the MCP2515.

In this course it is used to:

  • Connect the STM32F411 to a CAN bus over SPI
  • Exchange messages between CAN nodes
  • Observe CAN bus traffic

Image

MCP2515 + TJA1050 CAN bus module

MCP2515 + TJA1050 CAN bus module (HW-184). Source: AliExpress


Key Specifications

  • CAN controller: Microchip MCP2515, CAN 2.0B (standard and extended frames), up to 1 Mbit/s
  • MCU interface: SPI, up to 10 MHz, SPI modes 0,0 and 1,1
  • Transceiver: NXP TJA1050, high-speed CAN (ISO 11898), up to 1 Mbit/s
  • Power supply: TJA1050 4.75-5.25V; MCP2515 2.7-5.5V
  • Crystal: 8 MHz or 16 MHz (see below)
  • Termination: 120 Ω, enabled with jumper J1
  • Interrupt output: INT, active LOW

⚠ Crystal frequency: to be confirmed. Read the marking on the crystal of the delivered batch (8.000 or 16.000). All modules for a group must have the same frequency, so that every student works with the same setup.


How It Works

  1. The MCU writes a message (ID and payload) into an MCP2515 transmit buffer over SPI and requests transmission.
  2. The MCP2515 handles the CAN protocol and outputs the bit stream on TXCAN.
  3. The TJA1050 converts it into a differential signal on CANH/CANL.
  4. In the other direction, the TJA1050 converts bus signals back into a logic stream on RXCAN.
  5. Received messages that pass the filters are stored in receive buffers, and the INT pin tells the MCU to read them.

Basic Circuit / Connection

Target board: STM32F411 (Black Pill), SPI2.

Module Pin STM32F411 Connection Notes
VCC 5V pin of the board (from USB) TJA1050 needs 5V
GND GND Common ground
CS PB12 GPIO output, software chip select, active LOW
SCK PB13 SPI2_SCK
SO PB14 SPI2_MISO
SI PB15 SPI2_MOSI
INT PA8 GPIO input with EXTI, active LOW
CANH CANH of the other node Twisted pair
CANL CANL of the other node Twisted pair
J1 - Fitted only on the two end nodes of the bus

All STM32F411 pins above are FT (5V tolerant) in digital mode. Do not use PA0 or PB5 (not FT), and never configure these pins as analog.

Module schematic: MCP2515 module schematic


Important Electrical Notes

  • Do not connect this module directly to an ESP32-S3. With VCC = 5V the SO and INT outputs go up to about 5V (VOH ≥ VDD − 0.5V for SO), while ESP32-S3 GPIOs accept at most VDD + 0.3V ≈ 3.6V.
  • For the ESP32-S3, use the built-in TWAI controller with a 3.3V transceiver.
  • The module cannot be powered from 3.3V: the TJA1050 needs 4.75-5.25V and keeps the bus idle below 4.75V.
  • STM32F411: SO and INT can go to FT pins directly, because FT pins are 5V tolerant in digital mode only.
  • MCU to module direction: at VDD = 5V the MCP2515 guarantees a HIGH level on SCK, SI and CS only from 0.7 × VDD = 3.5V, while a 3.3V MCU outputs at most 3.3V.
  • Set the crystal frequency in the driver to the actual crystal on the board.
  • Use exactly two 120 Ω terminations, at the two ends of the bus.

Basic Calculations

Time Quantum

\[ TQ = \frac{2 \times (BRP + 1)}{F_{OSC}} \]

For an 8 MHz crystal and BRP = 0:

\[ TQ = \frac{2}{8\,MHz} = 0.25\,\mu s \]

At 500 kbit/s one bit lasts:

\[ \frac{1}{500\,000} = 2\,\mu s = 8\,TQ \]

With a 16 MHz crystal and the same BRP, TQ = 0.125 µs, so 2 µs = 16 TQ.

Crystal Mismatch

If the driver is set for 16 MHz but the crystal is 8 MHz, all bit times double. The node runs at 250 kbit/s instead of 500 kbit/s and cannot talk to the other nodes.

Termination

Two 120 Ω resistors in parallel:

\[ R = \frac{120 \times 120}{120 + 120} = 60\,\Omega \]

Measure about 60 Ω between CANH and CANL with the power off.


Typical Use in This Course

  • Two STM32F411 nodes exchanging messages over CAN
  • One STM32F411 + MCP2515 module on one end, a USB-CAN adapter on the other
  • Observing bus traffic in listen-only mode (for example, a wireless sniffer)

Common Student Mistakes

  • Connecting the module directly to an ESP32-S3, which puts 5V on the GPIO: use TWAI with a 3.3V transceiver instead
  • Wrong crystal frequency in code, so initialization fails or there is no communication: read the crystal marking and set 8 or 16 MHz
  • No termination, or J1 fitted on every module (bus errors): measure about 60 Ω between CANH and CANL with the power off
  • CANH and CANL swapped between nodes: connect H to H and L to L
  • Testing a single node in normal mode: use loopback mode or a second node

Advantages

  • Adds CAN to the STM32F411, which has no CAN peripheral, through a standard SPI interface
  • Hardware masks, filters and buffers reduce the load on the MCU
  • Low-cost and widely documented module

Limitations

  • Classic CAN 2.0B only, no CAN FD; up to 8 data bytes per frame
  • Needs a 5V supply for the TJA1050, so it is not suitable for direct use with 3.3V-only MCUs such as the ESP32-S3
  • SPI access adds latency compared with an on-chip CAN controller
  • Board variants (crystal, jumper, power routing) differ between sellers and must be checked on the delivered batch

Datasheet


Summary

The MCP2515 + TJA1050 module adds CAN to the STM32F411 over SPI:

  • Do not connect it directly to the ESP32-S3
  • Power it from 5V
  • Confirm the crystal frequency before writing the driver config
  • Fit the termination jumper only on the two end nodes
  • Use only FT pins on the STM32F411