Loading...
Searching...
No Matches
mcp2515_spi.h File Reference

Driver for the Microchip MCP2515 can controller. More...

Detailed Description

Driver for the Microchip MCP2515 can controller.

Definition of the MCP2515 SPI driver.

Author
Toon Stegen toon..nosp@m.steg.nosp@m.en@al.nosp@m.tran.nosp@m..com

Definition in file mcp2515_spi.h.

#include <stdint.h>
#include "candev_mcp2515.h"
+ Include dependency graph for mcp2515_spi.h:

Go to the source code of this file.

int mcp2515_spi_init (const candev_mcp2515_t *dev)
 Initialize SPI interface.
 
int mcp2515_spi_reset (const candev_mcp2515_t *dev)
 Reset MCP2515 device though SPI interface.
 
int mcp2515_spi_read (const candev_mcp2515_t *dev, uint8_t addr, uint8_t *buf, unsigned int len)
 Read the register value corresponding to addr.
 
int mcp2515_spi_read_rxbuf (const candev_mcp2515_t *dev, uint8_t mailbox, void *buf, uint8_t len)
 Read the can data received in the rx mailbox.
 
int mcp2515_spi_write (const candev_mcp2515_t *dev, uint8_t addr, uint8_t *buf, unsigned int len)
 Send the register value corresponding to addr.
 
int mcp2515_spi_write_txbuf (const candev_mcp2515_t *dev, uint8_t mailbox, void *buf, uint8_t len)
 Send the can data to the tx mailbox.
 
int mcp2515_spi_rts (const candev_mcp2515_t *dev, uint8_t mailbox)
 Initiate message transmission.
 
uint8_t mcp2515_spi_read_status (const candev_mcp2515_t *dev)
 Read MCP2515 status over SPI interface.
 
int mcp2515_spi_rx_status (const candev_mcp2515_t *dev)
 Read MCP2515 receive status over SPI interface.
 
int mcp2515_spi_bitmod (const candev_mcp2515_t *dev, uint8_t addr, uint8_t mask, uint8_t buf)
 Bit modify instruction.
 

Function Documentation

◆ mcp2515_spi_bitmod()

int mcp2515_spi_bitmod ( const candev_mcp2515_t dev,
uint8_t  addr,
uint8_t  mask,
uint8_t  buf 
)

Bit modify instruction.

The Bit Modify instruction provides a means for setting or clearing individual bits in specific status and control registers. This command is not available for all registers. Executing this command on registers that are not bit-modifiable will force the mask to FFh.

Parameters
[in]devdevice descriptor
[in]addrregister address
[in]maskmask to modify individual bit
[in]bufregister value
Returns
0 on success
<0 on error

◆ mcp2515_spi_init()

int mcp2515_spi_init ( const candev_mcp2515_t dev)

Initialize SPI interface.

The device descriptor contains all information related to the SPI interface.

Parameters
[out]devdevice descriptor
Returns
0 on success
<0 on error

◆ mcp2515_spi_read()

int mcp2515_spi_read ( const candev_mcp2515_t dev,
uint8_t  addr,
uint8_t *  buf,
unsigned int  len 
)

Read the register value corresponding to addr.

Parameters
[in]devdevice descriptor
[in]addrregister addr
[out]bufbuffer to receive register value
[in]lenlength of register value
Returns
0 on success
<0 on error

◆ mcp2515_spi_read_rxbuf()

int mcp2515_spi_read_rxbuf ( const candev_mcp2515_t dev,
uint8_t  mailbox,
void *  buf,
uint8_t  len 
)

Read the can data received in the rx mailbox.

Parameters
[in]devdevice descriptor
[in]mailboxrx mailbox
[out]bufbuffer to receive can data
[in]lenlength of can data
Returns
0 on success
<0 on error

◆ mcp2515_spi_read_status()

uint8_t mcp2515_spi_read_status ( const candev_mcp2515_t dev)

Read MCP2515 status over SPI interface.

Parameters
[in]devdevice descriptor
Returns
the read status

◆ mcp2515_spi_reset()

int mcp2515_spi_reset ( const candev_mcp2515_t dev)

Reset MCP2515 device though SPI interface.

The MCP2515 device is reset by sending the right message over SPI interface.

Parameters
[in]devdevice descriptor
Returns
0 on success
<0 on error

◆ mcp2515_spi_rts()

int mcp2515_spi_rts ( const candev_mcp2515_t dev,
uint8_t  mailbox 
)

Initiate message transmission.

The RTS command can be used to initiate message transmission for one or more of the transmit buffers.

Parameters
[in]devdevice descriptor
[in]mailboxmailbox to enable transmission
Returns
0 on success
<0 on error

◆ mcp2515_spi_rx_status()

int mcp2515_spi_rx_status ( const candev_mcp2515_t dev)

Read MCP2515 receive status over SPI interface.

Parameters
[in]devdevice descriptor
Returns
0 on success
<0 on error

◆ mcp2515_spi_write()

int mcp2515_spi_write ( const candev_mcp2515_t dev,
uint8_t  addr,
uint8_t *  buf,
unsigned int  len 
)

Send the register value corresponding to addr.

Parameters
[in]devdevice descriptor
[in]addraddress to write
[in]bufbuffer containing register data
[in]lenbuffer length
Returns
0 on success
<0 on error

◆ mcp2515_spi_write_txbuf()

int mcp2515_spi_write_txbuf ( const candev_mcp2515_t dev,
uint8_t  mailbox,
void *  buf,
uint8_t  len 
)

Send the can data to the tx mailbox.

Parameters
[in]devdevice descriptor
[in]mailboxtx mailbox
[in]bufbuffer containing can data
[in]lenbuffer length
Returns
0 on success
<0 on error