40 February 2017
bytes for an 11-bit address, two bytes for an extended
address ( 18 additional bits), a byte that stores the number
of data bytes in a message, and those data bytes. (How
can you put an 18-bit address in two bytes?
The SIDL registers hold the two “extra” address bits,
EID17 and EID16.)
In the MCP2515 datasheet, Table 11-1 shows
what looks like a CANSTAT and a CANCTRL register
for each buffer. Not so. An MCP2515 has only two
registers that affect the CAN-controller and govern
operating modes, provide buffer-interrupt signals,
and set clock parameters. The datasheet calls all
these bytes “registers,” so I’ll use that term from
now on. An MCP2515 includes other registers that
control flag bits and CAN bus bit rates.
Application software may identify a register by
its address and then read from it or write to it.
Register addresses run in sequence from 0x00 to
0x7F, but you needn’t try to memorize TXB0CTRL =
0x30, RXB1D0 = 0x76, and so on. Two C/C++ files
— MCP2515JT.h and MCP2515JT.cpp — define
register names and their addresses, which simplify
programming and make code easier to understand.
An MCP2515 CAN-controller operates in one
of five modes: Normal, Loopback, Configuration,
Sleep, and Listen, as set by software. The Normal
mode needs little explanation; it lets the IC operate
as a device on a CAN bus (with a driver IC, of
course). The Loopback mode “disconnects” the TXCAN
and RXCAN signals from a bus driver and internally
connects them. This mode lets people test the transmitter
and receiver without disturbing other devices on a bus.
This mode does not let you view the TXCAN signal with a
scope or logic analyzer,
however. (The Sleep and
Listen modes go beyond
this article’s scope.)
mode provides the only
way to change the
communication bit rate,
load the filter and mask
registers, and preset several
I/O pins. The MCP2515
enters this mode when it
receives power, when it
detects an external /RESET
signal (logic 0), or when it
receives a Reset command
(0xC0). This command
would come from an MCU
via its SPI connection.
Although an MCP2515
contains 114 registers, the
SPI port needs only nine
commands to read and
write data, modify a
specific bit, cause a reset,
TABLE 1. SPI Instruction Set for MCP2515
Instruction Name Instruction Description
RESET 0xC0: Reset registers to default settings, enter Configuration mode.
READ 0x03: Read a register’s content as a byte.
Read RX Buffer
0x90: Read receiver buffer 0 ID.
0x92: Read receiver buffer 0 Data.
0x94: Read receiver buffer 1 ID.
0x96: Read receiver buffer 1 Data.
WRITE 0x02: Write a byte to a register.
Load TX Buffer
0x40: Load transmitter buffer 0 ID.
0x41: Load transmitter buffer 0 Data.
0x42: Load transmitter buffer 1 ID.
0x43: Load transmitter buffer 1 Data.
0x44: Load transmitter buffer 2 ID.
0x45: Load transmitter buffer 2 Data.
0xA0: Read the following bits as one byte:
D0: Receive-Buffer-0-Full Interrupt Flag
D1: Receive-Buffer-1-Full Interrupt Flag
D2: Buffer 0, Message-Transmit-Request bit
D3: Transmit Buffer-0-Empty Interrupt Flag bit
D4: Buffer 1, Message-Transmit-Request bit
D5: Transmit Buffer-1-Empty Interrupt Flag bit
D6: Buffer 2, Message-Transmit-Request bit
D7: Transmit Buffer-2-Empty Interrupt Flag bit
RX STATUS 0xB0: Read bits to indicate a filter match and message type.
BIT MODIFY 0x05: Set or clear individual bits in a register. (Does not apply to all registers.)
Request to send a
0x81: Request to transmit message in buffer 0.
0x82: Request to transmit message in buffer 1.
0x84: Request to transmit message in buffer 2.
FIGURE 2. Register arrangement for receiver buffer RXB0 and
transmitter buffer TXB0. Other buffers have the same register
arrangement. Software may address these registers individually or