Driver for the Microchip MCP2515 can controller.
More...
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"
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.
|
|
◆ 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] | dev | device descriptor |
[in] | addr | register address |
[in] | mask | mask to modify individual bit |
[in] | buf | register value |
- Returns
- 0 on success
-
<0 on error
◆ mcp2515_spi_init()
Initialize SPI interface.
The device descriptor contains all information related to the SPI interface.
- Parameters
-
[out] | dev | device 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] | dev | device descriptor |
[in] | addr | register addr |
[out] | buf | buffer to receive register value |
[in] | len | length 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] | dev | device descriptor |
[in] | mailbox | rx mailbox |
[out] | buf | buffer to receive can data |
[in] | len | length of can data |
- Returns
- 0 on success
-
<0 on error
◆ mcp2515_spi_read_status()
Read MCP2515 status over SPI interface.
- Parameters
-
- Returns
- the read status
◆ mcp2515_spi_reset()
Reset MCP2515 device though SPI interface.
The MCP2515 device is reset by sending the right message over SPI interface.
- Parameters
-
- Returns
- 0 on success
-
<0 on error
◆ mcp2515_spi_rts()
Initiate message transmission.
The RTS command can be used to initiate message transmission for one or more of the transmit buffers.
- Parameters
-
[in] | dev | device descriptor |
[in] | mailbox | mailbox to enable transmission |
- Returns
- 0 on success
-
<0 on error
◆ mcp2515_spi_rx_status()
Read MCP2515 receive status over SPI interface.
- Parameters
-
- 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] | dev | device descriptor |
[in] | addr | address to write |
[in] | buf | buffer containing register data |
[in] | len | buffer 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] | dev | device descriptor |
[in] | mailbox | tx mailbox |
[in] | buf | buffer containing can data |
[in] | len | buffer length |
- Returns
- 0 on success
-
<0 on error