mcp2515

package
v0.0.0-...-2e22e3b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package mcp2515 implements a driver for the MCP2515 CAN Controller.

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

Reference: https://github.com/coryjfowler/MCP_CAN_lib

Package mcp2515 implements a driver for the MCP2515 CAN Controller.

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

Index

Constants

View Source
const (
	Clock16MHz = 1
	Clock8MHz  = 2

	CAN5kBps    = 1
	CAN10kBps   = 2
	CAN20kBps   = 3
	CAN25kBps   = 4
	CAN31k25Bps = 5
	CAN33kBps   = 6
	CAN40kBps   = 7
	CAN50kBps   = 8
	CAN80kBps   = 9
	CAN83k3Bps  = 10
	CAN95kBps   = 11
	CAN100kBps  = 12
	CAN125kBps  = 13
	CAN200kBps  = 14
	CAN250kBps  = 15
	CAN500kBps  = 16
	CAN666kBps  = 17
	CAN1000kBps = 18
	CAN47kBps   = 19
)
View Source
const DebugEn = 0

Variables

This section is empty.

Functions

This section is empty.

Types

type CANMsg

type CANMsg struct {
	ID   uint32
	Dlc  uint8
	Data []byte
	Ext  bool
	Rtr  bool
}

CANMsg stores CAN message fields.

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device wraps MCP2515 SPI CAN Module.

func New

func New(b drivers.SPI, csPin machine.Pin) *Device

New returns a new MCP2515 driver. Pass in a fully configured SPI bus.

func (*Device) Begin

func (d *Device) Begin(speed byte, clock byte) error

Begin starts the CAN controller.

func (*Device) Configure

func (d *Device) Configure()

Configure sets up the device for communication.

func (*Device) Received

func (d *Device) Received() bool

Received returns true if CAN message is received.

func (*Device) Reset

func (d *Device) Reset() error

Reset resets mcp2515.

func (*Device) Rx

func (d *Device) Rx() (*CANMsg, error)

Rx returns received CAN message.

func (*Device) Tx

func (d *Device) Tx(canid uint32, dlc uint8, data []byte) error

Tx transmits CAN Message.

type SPI

type SPI struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL