Skip to content

Micropython external C module for MCP2515 (For high speed)

License

Notifications You must be signed in to change notification settings

Wizapply/mpy-module-mcp2515

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mpy-module-mcp2515

License: MIT

Overview

Micropython external C module for MCP2515 (For high speed)

MCP2515 : Stand Alone CAN Controller with SPI
https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf

Usage

#linux

git clone https://www.github.com/micropython/micropython
cd micropython/
git clone https://github.com/Wizapply/mpy-module-mcp2515 mcp2515
cd mcp2515
make

Example micropython(.py) code:

import mcp2515
import time
from machine import Pin, SPI

sckPin = 6
mosiPin = 7
misoPin = 4
csPin = 5

spio = SPI(0, 8_000_000, sck=Pin(sckPin), mosi=Pin(mosiPin), miso=Pin(misoPin))
pin_cs = Pin(csPin, Pin.OUT)
if not mcp2515.can_init(spio,pin_cs,500000):
    print('mcp2515 error.')

mcp2515.can_filter(0x700,0x700,False)
mcp2515.can_mode(mcp2515.NormalMode)

while True:
    while mcp2515.can_recv_poling() > 0:
        data = mcp2515.can_read()
        if not data is None:
            mcp2515.can_send(0x666,data[1],0)
    time.sleep_ms(10)

Performance

Repeat: Receive to Send
CAN Config: 500000 bps Standard Frame
Send Can Frame: ID:0x777 dlc:8 byte:0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

Micropython scripts Only This Codes Performance
RP2040 270~340 Messages/s 1200~1400 Messages/s x4.0~4.3 faster

Library used

About

Micropython external C module for MCP2515 (For high speed)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published