There are several windows associated with the Register template: MCP2515 EVALUATION BOARD WINDOW This window displays the connection status, parallel port address and MCP2515 mode of ope
Trang 1M AN873
INTRODUCTION
The MCP2515 eases software development and
shortens the learning curve for the MCP2515 by
providing three PC software templates with different
functions that CAN node designers can use as needed
By using one of the templates, the user can read,
display, and modify all of the registers in the MCP2515
down to the bit level Another template can
demonstrate basic input/output functionality by
allowing messages to be transmitted and received on
the CAN bus Finally, the third template is a
demonstration template that, by using a
preprogrammed PICmicro® microcontroller (MCU),
implements a two node CAN bus that gets the user “on
the bus” in the shortest amount of time and effort
This application note serves as a three-part tutorial for
the MCP2515 and discusses the three software
templates in detail as well as the important menu items
Figure 1 is a block diagram of the MCP2515 board The
board is a two node CAN system that can be used
together to implement a simple bus or can be
connected to an external bus using the off-board
connector For the purposes of this application note,
the left node will be referred to as the PC node and the right node will be referred to as the PICmicro node.
Both nodes are identical except for the controller interface to the MCP2515 is a PC for one node and a PICmicro controller for the other node By providing a two node CAN network on a single board, a simple CAN network can be implemented with one PCB
PC Node
The left node (as oriented in Figure 1) is referred to as the PC node The PC performs the microcontroller functions and interfaces to the MCP2515 via Serial Peripheral Interface (SPI™) through the parallel port The software templates control this node
PICmicro Node
The right node is referred to as the PICmicro node and represents a typical CAN node This node is used by the end user as needed When running the “MCP2515 Evaluation” template, demonstration firmware is used
to complete a CAN system
Author: Pat Richards
Microchip Technology Inc.
To PC
ank M C
SPI™
SPI™
ank M C
PC Node PICmicro ® Node
Using the MCP2515 CAN Developer’s Kit
Trang 2OVERVIEW OF THE SYSTEM
SOFTWARE
There are three software templates that are used to
control one or both of the nodes on the board This
tutorial will discuss all three of the templates Refer to
the User’s Guide for images of the windows if needed
The following is a brief discussion of the three
templates:
Register Template
The “Register” template is a low-level template that
allows bit-level control of the MCP2515 registers This
template may be used to become familiar with the
MCP2515 by experimenting with mask and filter
settings, bit timings, configuration registers and other
functions associated with configuring the MCP2515
There are several windows associated with the
Register template:
MCP2515 EVALUATION BOARD WINDOW
This window displays the connection status, parallel
port address and MCP2515 mode of operation The
MCP2515 can be reset in this window and MCP2515
register contents be saved and loaded The register
contents are saved as a HEX file
STATUS WINDOW
The status window shows the contents of CANSTAT
register (operation mode and interrupt flag codes), TX
and RX error counts (TEC and REC registers) and
EFLG register contents
In addition, there are buttons to clear the overflow flag
bits in the EFLG register
MESSAGE FILTERS WINDOW
The masks and filters are configurable in this window,
allowing the user to setup and test for message
acceptance The ‘Message Filters’ window allows
messages to be tested against the masks and filters
without physically going on the bus This is
accomplished by entering values in the mask, filters
and test identifier fields and pressing the “Test Buf n”
button
PHYSICAL LAYER WINDOW The three CNF registers used for all CAN bit timings are configured in this window
CONFIGURATION WINDOW TXRTSCTRL, BFPCTRL, CANINTF, CANINTE and CANCTRL are all modified from this window These are the control and flag registers
If a message is received while in the Register template, the receive buffer flags in CANINTF (RX0IF and RX1IF) must be cleared manually to receive additional messages
TRANSMIT WINDOW The transmit window controls the buffer contents for the transmit registers including TXBnCTRL, the identifier registers and the data registers
RECEIVE WINDOW This window contains all of the buffer contents for the receive buffers including RXBnCTRL, the identifier registers and the data registers
Basic Template
This template provides high-level control of one node (PC node) and is identical to the “MCP2515 Evaluation” template, minus the window for the second node (see the tutorial, part 1) This template can be thought of as
a simple bus monitor with transmit capabilities BUS STATUS
This window, labeled ‘MCP2515 CAN Controller’, provides several pieces of information about the status
of the bus including nominal bus loading, status of node (ON or OFF the bus) and bus bit rate
OUTPUT The output window displays the messages that are received and transmitted A time stamp indicates either delta times or absolute times between messages (see
“Message Format Window” description)
HISTORY LIST The history list window is used to collect transmitted messages for saving to a file This file can be opened later and messages can be selected for retransmission Some or all messages can be selected for transmission This window works in conjunction with the ‘’Timed Transmission” window
For the demo program, the history list window is used
to send initial configuration data to the PICmicro® MCU
Note: The templates can be saved as projects
which will save the layout and default
properties by selecting File > Save Saving
the project does not save the register
contents of the MCP2515 Saving the
register contents can be done in the
Register template as discussed at the end
of the Register Template tutorial (Part 3)
Note: The masks and filters cannot be physically
written to the registers unless the
MCP2515 is in “Configuration” mode
Note: The CNF registers can only be modified
while the MCP2515 is in “Configuration” mode
Trang 3TIMED TRANSMISSIONS
The timed transmissions window is used to send the
messages in the history list The messages can be sent
either one time (one shot) or repeated at regular
inter-vals (cyclic)
MESSAGE FORMAT WINDOW
This window determines the format of the displayed
data in the output window The default is ‘Standard Text
Format’ which displays the message data as normal
data
To change the property of the “Standard Text Format”,
highlight “Standard Text Format” and press the
“Properties” button The numeric base and the time
display can be changed as indicated in Figure 2
OUTPUT WINDOW
MCP2515 Evaluation Template
This template contains a simple demonstration
program Only high-level control is possible on the PC
node Indirect control of the PICmicro node is made
possible via the CAN bus (i.e., the PICmicro node is
configured by the PC node via the CAN bus) The
demo program incorporates the CAN Kingdom Higher
Layer Protocol (HLP) A specific set up procedure
(covered later) is required to enable the two nodes to
communicate with each other
The windows associated with the Evaluation Template
are the same as the Basic template with the following
addition:
MCP2515 EVALUATION BOARD CONTROLS
WINDOW
This window, combined with the “Output” window, is the
main window of interest for the demo This window
displays the graphical representation of the messages
on the CAN bus
UNDERSTANDING THE MENUS
There are several menu items that are discussed in this application note The remaining menu items that are not discussed are the self-explanatory menus, such as
“File > Save” and “Help” The menus change slightly between the three software templates as discussed
Register Template Menus
The menu items for the Register template are shown in Figure 3
The three menus that are discussed are:
VIEW MENU This menu makes visible/invisible, the windows loaded
in the Register Template
MESSAGES MENU This menu loads windows associated with the Register Template
OPTIONS MENU The “Options” menu contains two sub-menu items that,
as the name implies, sets options for the software
Options > Global - as shown in Figure 4 has autosave
options and numeric base settings The numeric base settings select the default numeric base as displayed/ entered in the windows Selecting hexadecimal auto-matically places a ‘$’ in front of the entered number indicating the number entered is HEX
Note: Selecting a window while holding down the
shift key will load a copy of the window so that more than one window of the same type can be visible This is useful for opening multiple “Receive” and “Transmit” windows for viewing multiple buffers simultaneously
Trang 4FIGURE 4: OPTIONS > GLOBAL
Options > MCP2515 - as shown in Figure 5 sets the
clock frequency, parallel port address, and whether the
MCP2515 is reset on software power-up
The clock frequency and parallel port address must be
set properly for the software to function properly The
MCP2515 clock frequency is used in calculating the
CAN bus rate and is therefore required to be set The
parallel port address much match the BIOS address
setting Typical values for the parallel port are 0x3BC,
0x378, and 0x278 Address 0x378 is the most common
default for LPT1
FIGURE 5: OPTIONS > MCP2515
Basic and Demonstration Template Menus
The Basic and Demonstration Template menus are identical as shown in Figure 3 The sub-menus are same for the Basic and Demonstration templates However, they differ from the Register template sub-menus as follows:
MESSAGES MENU The “Messages” contains two sub menus that select transmit message formats
Messages > Universal > Universal - (shown in
Figure 6) loads a window used for transmitting mes-sages onto the CAN bus The identifier, data length, and data are entered and sent with this window The
“Universal” window can be thought of as a window for sending raw/unformatted messages Other windows under “Messages > Universal” change the formatting of how outgoing messages are entered For example, transmitted messages can be entered as integers, floats, longs or strings by selecting the proper sub-menu
FIGURE 6: MESSAGES > UNIVERSAL
>UNIVERSAL
Messages > CAN Kingdom - this sub menu is for sending CAN Kingdom formatted messages and is beyond the scope of this application note
OPTIONS MENU The “Options” menu is identical to the “Options” menu
in the “Register Template” except for the addition of a
“King’s Pages” sub-menu which is beyond the scope of this application note
Trang 5TUTORIAL PART 1: SETTING UP AND
RUNNING THE DEMO
The MCP2515 CAN Development Kit demo utilizes
both of its CAN nodes to demonstrate basic CAN
communications Each node is set up to transmit and
receive messages
Initial Set Up
A few initial set up procedures should be performed to
insure proper operation before continuing
VERIFY/SET THE PARALLEL PORT ADDRESS
The parallel port address must match the operating
system BIOS setting To set/verify, select “Options >
MCP2515 ”
SET OSCILLATOR FREQUENCY IN
SOFTWARE
The oscillator frequency must be set to match the
board oscillator so the CAN bit rate will be reflected
accurately To set, select “Options > MCP2515 ” and
set to the proper oscillator frequency (16000 kHz if
using the 16 MHz oscillator supplied with the kit)
SAVE CONFIGURATION
Saving the configuration as a project insures that the
new settings are saved To save, select “File > Save”
and name the project something descriptive
REOPEN SAVED PROJECT
This refreshes the settings to the saved values To
reopen, select “File > Reopen” and choose the file that
was just saved
Running the Demo
Open a new “MCP2515 Evaluation Board” project template (File > New)
Refer to Figure 7 for the configuration procedure After stepping through the configuration procedure, the two nodes should be communicating with each other A receive message (received by the PC node) should be displayed in the “Output” window at every timer interval
as set in the “MCP2515 Evaluation Board Controls” window ($100 or 256 ms in the case of the flow diagram) The data contains the potentiometer value and the S4, S5, S6 button status as read by the PICmicro node
Trang 6FIGURE 7: DEMO CONFIGURATION PROCEDURE
SetFosc = 16 MHz
Set numeric base to HEX
Set “Display” output to HEX
Set bit rate = 125 kb/s
Go “on-bus”
Send configuration data to
Set transmit rate for PICmicro PICmicro node
node
Communicate
Must set the on-board oscillator value so the bit timing will be calculated properly
(Options > MCP2515)
Sets the default numeric base for entered numbers and places ‘$’ in front of the number
(Options > Global)
Configures the “Output” window display
(Highlight “Standard Text Format” in the “Select Formatters” window and press
“Properties”).
Select the “Bus Parameters” tab in
the “MCP2515 Can Controller”
window and set the bit rate
Select the “Bus Statistics” tab in
the “MCP2515 CAN Controller”
window and press “Go on Bus”
Open “History List” Window
(View > History List)
Load configuration messages
(Press “Load” and select
“mcsetup.hst”)
Send messages to PICmicro node
(Press “Send All”)*
Set “Timer Rate” in the “MCP2515
Evaluation Board Controls” window
to $100 (=> 256 ms)
The PICmicro node should now be sending sensor status (POT and S4, S5, S6 buttons) at 256 ms intervals
* The “Output” window should display some transmitted messages and two received messages If both receive messages are not displayed, reset the nodes by pressing MCLR on the PICmicro node and “Reset Board” button on the PC node and go to the “Go on-bus” step
Trang 7Two transmit messages can be displayed in the
“Output” window by checking/unchecking the LED
boxes or by pressing the “Set” button to set the transmit
interval time These controls are contained in
the”MCP2515 Evaluation Board Controls” window
The function of each node is explained in more detail
below
PC Node
The PC node is set up to receive and display all
messages sent by the PICmicro node (in the “Output”
window) The received messages contain
potentiometer data and button status (S4, S5, S6) and
are displayed graphically in the “MCP2515 Evaluation
Board Controls” window The “raw” message is
displayed in the “Output” window
The PC node can transmit two message types:
1 The timer rate that the PICmicro node uses to
schedule its message transmissions
2 The digital output of the RXnBF pins, which are
indicated on the associated LEDs These pins
on the MCP2515 are configured as general
purpose outputs for the purpose of the demo
The messages are transmitted by either pressing the
“Set” button or checking/unchecking the LED
checkboxes in the “MCP2515 Evaluation Board
Controls” window (Figure 8)
BOARD CONTROLS
PICmicro Node
The PICmicro node is set up to respond to messages received by the PC node This response will either involve changing it’s own transmit interval or driving the RXnBF pins which are reflected on corresponding LEDs
The PICmicro node will transmit a single message at the predefined transmit interval ($100 ms, or 256 ms for the tutorial) which contains the ADC value from the potentiometer in byte 1 This message also contains the button status for S4, S5, and S6 in byte 0
Message Formats
There are three different message identifiers that are used in the system implementation Each identifier indicates a specific function as explained in Table 1
n - represents changing data
Trang 8SCHEDULED TRANSMISSION FREQUENCY
(MESSAGE 066)
This message is sent from the PC node when “Set” is
pressed and contains (in DB1 and DB2) the frequency
in which the PICmicro node is to send data The “Timer
Rate” text box sets the transmission frequency The
format of the data is:
• DB2 - eight MSbs of the transmission frequency
• DB1 - the six LSbs of the transmission frequency
Example: if the “Timer Rate” is set to 0xFFFF, the
resulting data in the message would be:
• DB1 = FC, DB2 = FF
This implies that the actual maximum = 0x3FFF =
16,383 => 16.383 seconds
Example: if the “Timer Rate” = 0x100 (256 ms), as in
the flow diagram The resulting data in the message
would be DB1 = 00, DB2 = 40
LED CONTROL (MESSAGE 067)
This message is sent from the PC node and is used to
control the RXBFn LEDs on the PICmicro node
The format of the data is:
• LED RXFB0 - DB0, bit0; (0 = OFF, 1 = ON)
• LED RXFB1 - DB0, bit1, (0 = OFF, 1 = ON)
POTENTIOMETER AND BUTTONS (MESSAGE
069)
This message is scheduled and is sent from the
PICmicro node The message is sent at regular
intervals as determined by message ‘066’ and contains
the digital equivalent of the potentiometer and the
button status for the three buttons associated with the
PICmicro node For each button, there is one bit
showing the current status and one sticky bit that is set
if the button has been pressed since the last poll
The format of the data:
• DB0 - button status (six MSbs => three status bits
and three sticky bits)
• DB1 - analog-to-digital converted value
TUTORIAL PART 2: THE BASIC TEMPLATE
The “Basic” template is identical to the “MCP2515 Evaluation” template in every aspect except that the
“MCP2515 Evaluation Board Controls” is not available
in the “Basic” template Therefore, this tutorial will focus
on the different settings/configurations available
Changing the Output Window
The “Output” window is the main window of activity in the “Basic” template and can be modified to different display properties
SCROLLING AND FIXED MESSAGES The messages can be displayed in either scrolling or fixed format simply by clicking the right mouse button while the cursor is over the “Output” window and selecting the proper display properties (Figure 9)
Scrolling Messages - deselect “Fixed Positions”.
Selecting “Auto Scroll” automatically scrolls the window
to the newest message
Non-scrolling Messages - Select “Fixed Positions”.
This selection anchors messages with matching identifiers into one position; only the data and time are updated
CHANGING THE TIME BASE The “Time” can be displayed as either free-running time between messages or as delta time by highlighting
“Standard Text Format” in the “Select Formatters” window and pressing the “Properties” button (see Figure 2)
WINDOW DISPLAY PROPERTIES
Note: If the Demo Tutorial (Part 1) was set up
prior to this one, the PICmicro node is probably still sending messages at regular intervals Setting the CAN bit rate to
125 kb/s and going on the bus will display these messages in the “output” window
Trang 9TUTORIAL PART 3: THE REGISTER
TEMPLATE
As described earlier, the “Register” template is a low
level template that allows bit-level control of the
MCP2515 registers This template may be used to
become familiarized with the MCP2515 by
experimenting with mask and filter settings, bit timings,
configuration registers, and other functions associated
with configuring the MCP2515
This tutorial will discuss the associated windows and
provide examples for some In addition, a Loopback
mode demonstration will be given to demonstrate the
basic steps required for successful CAN
communications with the MCP2515
Initial Set Up
A few initial set up procedures should be performed to
insure proper operation before continuing
VERIFY/SET THE PARALLEL PORT ADDRESS
The parallel port address must match the operating
system BIOS setting To set/verify, select “Options >
MCP2515 ”
SET OSCILLATOR FREQUENCY IN
SOFTWARE
The oscillator frequency must be set to match the
board oscillator so the CAN bit rate will be reflected
accurately To set, select “Options > MCP2515 ” and
set to the proper oscillator frequency (16000 kHz if
using the 16 MHz oscillator supplied with the kit)
SAVE CONFIGURATION
Saving the configuration as a project insures that the
new settings are saved To save, select “File > Save”
and name the project something descriptive
REOPEN SAVED PROJECT
This refreshes the settings to the saved values To
reopen, select “File > Reopen” and choose the file that
Mask and Filter Settings
The “MCP2515 Message Filters” window can be used
to experiment with various mask and filter configurations and how these configurations apply to incoming message IDs For example, setting “RXM0”,
“RXF0”, “RXF1”, and “Test Identifier” as shown in Figure 10 would reveal that the Test Identifier would match RXF1 and be accepted into buffer 0 Pressing the “Test Buf n” buttons is a software test of the masks and filters
Refer to the MCP2515 data sheet for more details on mask and filter operations
FILTERS
When finished setting the mask and filters, the MCP2515 can be written by pressing the “Write” button while in “Configuration” mode
IMPORTANT CONSIDERATIONS
• The mask/filter and CNF registers are not written unless the “Write” button is pressed while the MCP2515 is in Configuration mode
• An ‘x’ at the end of a value indicates “extended” identifier (29 bits) If a filter value has an ‘x’, the incoming identifier will be accepted only if it also is extended (contains an ‘x’)
• The’$’ represents HEX
• Standard identifiers are 11-bits with a range of
$0 - $7FF
• Extended identifiers are 29-bits with a range of
$0 - $7FFFFFFE
Note: Unlike the “Basic” and “Evaluation”
templates which modify specific registers
automatically, all registers of the MCP2515
while in the “Register” template are
controlled manually (e.g transmit requests
are set manually and the receive flags
must be cleared manually for each
message sent and received) In essence,
the user is the microcontroller while in the
“Register” template
Trang 10Bit Timing
The “MCP2515 Physical Layer” window contains the
three CNF registers which are used to set the CAN bit
rate The resulting bit rate is displayed at the bottom of
the window for a given FOSC and CNF register values
FIGURE 11: PHYSICAL LAYER
WINDOW
Example, Figure 11 shows one possible configuration
of the bit timing registers for a CAN bit rate of 125 kb/s
using a 16 Mhz oscillator
Configuration Window
This window contains the configuration registers as
shown in Figure 12 The following examples are
provided to become familiar with the register
operations:
TXRTSCTRL
This register configures the TXnRTS pins as either
request-to-send pins for their associated transmit
buffers or as general purpose inputs
Setting bits 2:0 = b’00’ configures the pins as inputs
The operation of these pins as inputs can be tested by
pressing and holding one or more switches (S1, S2,
S3) and pressing “Read” Bits 5:0 will reflect the status
of the buttons
BFPCTRL
This register configures the two RXnBF pins as receive
buffer full pins, as general purpose outputs, or tri state
(off)
Setting bits 3:2 = b‘11’ and bits 1:0 = b‘00’ configures
the pins as outputs The associated RXBFn LEDs can
be toggled on/off by changing the values of bits 5:4 and
clicking “Write”
CANINTE AND CANINTF CANINTE is the interrupt enable register that routes it’s associated flag bit in CANINTF to the INT pin The flag bits in CANINTF can be set/cleared regardless of CANINTE
To demonstrate the interrupts, simply set a bit in CANINTE and toggle its associated bit in CANINTF The INT pin LED should toggle with the flag bit Example: Set CANINTE.RX0IE = 1 (bit 0) and then toggle CANINTF.RX0IF (bit 0) and click “Write” The INT LED will toggle with the flag bit
CANCTRL The CANCTRL register sets the operation mode and the CLKOUT prescaler
The operation mode can be changed by either selecting the mode from the pull-down menu or by toggling the three MSb
REGISTERS
Status Window
The “MCP2515 Status” window contains the status of several parameters including the mode of operation, pending interrupts, transmit and receive error counters values, and receive buffer overflow status
Transmit and Receive Registers
The transmit and receive registers are displayed in two separate windows and contain the identifier, data length code, and data registers The transmit register window also contains the CTRL (TXBnCTRL) register which contains the Transmit Request (TXREQ) bit (bit 3)
Note: The CNF registers can only be modified
while in “Configuration” mode Any other
mode will gray out the registers indicating
they are read-only