MCP ExplorerExplorer

Mcp2515

@Znooptokkieon a year ago
1 MIT
FreeCommunity
AI Systems
Standaard configuratie instellingen voor de MCP2515 8MHz.

Overview

What is Mcp2515

The MCP2515 is a standalone CAN (Controller Area Network) controller that operates at 8MHz, designed for communication with microcontrollers like the Raspberry Pi.

Use cases

Use cases for the MCP2515 include vehicle diagnostics, sensor data transmission in industrial systems, and communication between IoT devices in smart homes.

How to use

To use the MCP2515, connect it to a Raspberry Pi (either Raspberry Pi 5 or Raspberry Pi Pico) using SPI connections, configure the Raspberry Pi to enable SPI, and set up the necessary resistors for CAN communication.

Key features

Key features of the MCP2515 include support for CAN protocol, SPI interface for easy communication with microcontrollers, and compatibility with various Raspberry Pi models.

Where to use

The MCP2515 is commonly used in automotive applications, industrial automation, and any project requiring reliable communication between multiple microcontrollers over a CAN bus.

Content

MCP2515 CAN-Bus Communicatie met Raspberry Pi 5 en Raspberry Pi Pico

Notities

  • De code die zich in deze repo bevindt, is bedoelt voor de Pico, en neit voor de Raspberry PI 5. De library “machine” is namelijk niet geschikt voor de Raspberry PI 5

📌 Benodigdheden

  • Raspberry Pi 5 + MCP2515 CAN-module
  • Raspberry Pi Pico + MCP2515 CAN-module
  • 2 x 120 ohm weerstand
  • Jumper wires
  • Micro-USB-kabel voor de Raspberry Pi Pico

🛠️ Hardware aansluiten

CAN-bus bedrading

🔹 Zorg dat op beide MCP2515 modules een 120 ohm weerstand aanwezig is!

MCP2515 (Raspberry Pi 5) MCP2515 (Raspberry Pi Pico)
CAN_H (female jumper) CAN_H (male jumper)
CAN_L (female jumper) CAN_L (male jumper)

🔌 SPI-aansluitingen MCP2515 → Raspberry Pi 5

MCP2515 Raspberry Pi 5 (GPIO)
VCC 5V
GND GND
CS GPIO 8 (Pin 24, CE0)
SCK GPIO 11 (Pin 23, SCLK)
SI (MOSI) GPIO 10 (Pin 19, MOSI)
SO (MISO) GPIO 9 (Pin 21, MISO)
INT GPIO 25 (Pin 22, Optioneel)

🔌 SPI-aansluitingen MCP2515 → Raspberry Pi Pico

MCP2515 Raspberry Pi Pico (GPIO)
VCC 5V (Pin 40)
GND GND
CS GP17 (Pin 22)
SCK GP18 (Pin 24)
SI (MOSI) GP19 (Pin 25)
SO (MISO) GP16 (Pin 21)
INT GP20 (Optioneel)

🖥️ Raspberry Pi 5 configureren

SPI inschakelen

sudo raspi-config

Herstart de Raspberry Pi 5

sudo reboot

MCP2515 configureren

Open het configuratiebestand

sudo nano /boot/firmware/config.txt

Voeg de volgende regelst toe (of wijzig ze als ze al bestaan)

dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=8000000,interrupt=25

🔹 Opmerking: oscillator=8000000 is nodig omdat de MCP2515 een 8 MHz kristal gebruikt.

Sla op en herstart de Raspberry Pi 5 opnieuw

sudo reboot

🖧 CAN-interface activeren

Zet de CAN-interface aan met:

sudo ip link set can0 up type can bitrate 500000

Controleer of can0 actief is

ip link show can0

🖥️ Raspberry Pi Pico instellen

Flash MicroPython op de Pico

  1. Download de MicroPython UF2: MicroPython voor Raspberry Pi Pico
  2. Houd BOOTSEL ingedrukt, sluit de Pico via USB aan en sleep het UF2-bestand naar de "RPI-RP2" USB-schijf.
  3. De Pico start automatisch opnieuw op. (Zo niet, verwijder en sluit hem opnieuw aan.)
    • Als hij niet meer als USB-schijf verschijnt, is dat CORRECT!

Sluit Thonny aan op de Pico

  1. Open Thonny.
  2. Ga naar Interpreter > MicroPython (Raspberry Pi Pico).
  3. Druk op Verbinden.

🔍 Test de communicatie

Zorg eerst dat je candump correct hebt gedownload

sudo apt install can-utils

Start candump op de Raspberry Pi 5:

candump can0

Stuur een bericht naar de Pico vanaf de Raspberry Pi 5

cansend can0 123#11223344

🛠️ Troubleshooting

Probleem: De CAN-Bus zit in een error-modus (“bus-off”)
Controleer de MCP2515-status met:

dmesg | grep -i mcp

Oplossing: Reset de MCP2515 met de volgende commando’s

sudo dmesg -C
sudo rmmod mcp251x
sudo modprobe mcp251x

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers