Transcription of Using the MCP2515 CAN Developer's Kit
1 2003 Microchip Technology 1 MAN873 INTRODUCTIONThe MCP2515 eases software development andshortens the learning curve for the MCP2515 byproviding three PC software templates with differentfunctions that CAN node designers can use as Using one of the templates, the user can read,display, and modify all of the registers in the MCP2515down to the bit level. Another template candemonstrate basic input/output functionality byallowing messages to be transmitted and received onthe CAN bus. Finally, the third template is ademonstration template that, by Using apreprogrammed PICmicro microcontroller (MCU),implements a two node CAN bus that gets the user onthe bus in the shortest amount of time and application note serves as a three-part tutorial forthe MCP2515 and discusses the three softwaretemplates in detail as well as the important menu 1 is a block diagram of the MCP2515 board.
2 Theboard is a two node CAN system that can be usedtogether to implement a simple bus or can beconnected to an external bus Using the off-boardconnector. For the purposes of this application note,the left node will be referred to as the PC node and theright node will be referred to as the PICmicro nodes are identical except for the controllerinterface to the MCP2515 is a PC for one node and aPICmicro controller for the other node. By providing atwo node CAN network on a single board, a simpleCAN network can be implemented with one NodeThe left node (as oriented in Figure 1) is referred to asthe PC node. The PC performs the microcontrollerfunctions and interfaces to the MCP2515 via SerialPeripheral Interface (SPI ) through the parallel software templates control this NodeThe right node is referred to as the PICmicro node andrepresents a typical CAN node.
3 This node is used bythe end user as needed. When running the MCP2515 Evaluation template, demonstration firmware is usedto complete a CAN 1:BLOCK DIAGRAM OF MCP2515 DEVELOPMENT BOARDA uthor:Pat RichardsMicrochip Technology P CLED BankMCP2515 XCVRSPI SPI RXCANTXCAN CLED BankMCP2515 XCVRRXCANTXCANCANHCANLE xternalCAN BusPC NodePICmicro NodeUsing the MCP2515 CAN developer s KitAN873DS00873A-page 2 2003 Microchip Technology OF THE SYSTEM SOFTWARET here are three software templates that are used tocontrol one or both of the nodes on the board. Thistutorial will discuss all three of the templates. Refer tothe User s Guide for images of the windows if following is a brief discussion of the threetemplates:Register TemplateThe Register template is a low-level template thatallows bit-level control of the MCP2515 registers.
4 Thistemplate may be used to become familiar with theMCP2515 by experimenting with mask and filtersettings, bit timings, configuration registers and otherfunctions associated with configuring the are several windows associated with theRegister template: MCP2515 EVALUATION BOARD WINDOWThis window displays the connection status, parallelport address and MCP2515 mode of operation. TheMCP2515 can be reset in this window and MCP2515register contents be saved and loaded. The registercontents are saved as a HEX WINDOWThe status window shows the contents of CANSTAT register (operation mode and interrupt flag codes), TXand RX error counts (TEC and REC registers) andEFLG register addition, there are buttons to clear the overflow flagbits in the EFLG FILTERS WINDOWThe masks and filters are configurable in this window,allowing the user to setup and test for messageacceptance.
5 The Message Filters window allowsmessages to be tested against the masks and filterswithout physically going on the bus. This isaccomplished by entering values in the mask, filtersand test identifier fields and pressing the Test Buf n LAYER WINDOWThe three CNF registers used for all CAN bit timingsare configured in this WINDOWTXRTSCTRL, BFPCTRL, CANINTF, CANINTE andCANCTRL are all modified from this window. These arethe control and flag a message is received while in the Register template,the receive buffer flags in CANINTF (RX0IF andRX1IF) must be cleared manually to receive WINDOWThe transmit window controls the buffer contents forthe transmit registers including TXBnCTRL, theidentifier registers and the data WINDOWThis window contains all of the buffer contents for thereceive buffers including RXBnCTRL, the identifierregisters and the data TemplateThis 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 (seethe tutorial, part 1).
6 This template can be thought of asa simple bus monitor with transmit STATUSThis window, labeled MCP2515 CAN Controller ,provides several pieces of information about the statusof the bus including nominal bus loading, status of node(ON or OFF the bus) and bus bit output window displays the messages that arereceived and transmitted. A time stamp indicates eitherdelta times or absolute times between messages (see Message Format Window description).HISTORY LISTThe history list window is used to collect transmittedmessages for saving to a file. This file can be openedlater and messages can be selected for or all messages can be selected fortransmission. This window works in conjunction withthe Timed Transmission the demo program, the history list window is usedto send initial configuration data to the PICmicro :The templates can be saved as projectswhich will save the layout and defaultproperties by selecting File > Save.
7 Savingthe project does not save the registercontents of the MCP2515 . Saving theregister contents can be done in theRegister template as discussed at the endof the Register Template tutorial (Part 3).Note:The masks and filters cannot be physicallywritten to the registers unless theMCP2515 is in Configuration :The CNF registers can only be modifiedwhile the MCP2515 is in Configuration mode. 2003 Microchip Technology 3AN873 TIMED TRANSMISSIONSThe timed transmissions window is used to send themessages in the history list. The messages can be senteither one time (one shot) or repeated at regular inter-vals (cyclic).MESSAGE FORMAT WINDOWThis window determines the format of the displayeddata in the output window.
8 The default is Standard TextFormat which displays the message data as change the property of the Standard Text Format ,highlight Standard Text Format and press the Properties button. The numeric base and the timedisplay can be changed as indicated in Figure 2:TEXT FORMAT FOR OUTPUT WINDOWMCP2515 Evaluation TemplateThis template contains a simple demonstrationprogram. Only high-level control is possible on the PCnode. Indirect control of the PICmicro node is madepossible via the CAN bus ( , the PICmicro node isconfigured by the PC node via the CAN bus). Thedemo program incorporates the CAN Kingdom HigherLayer Protocol (HLP). A specific set up procedure(covered later) is required to enable the two nodes tocommunicate with each windows associated with the Evaluation Templateare the same as the Basic template with the followingaddition: MCP2515 EVALUATION BOARD CONTROLS WINDOWThis window, combined with the Output window, is themain window of interest for the demo.
9 This windowdisplays the graphical representation of the messageson the CAN THE MENUST here are several menu items that are discussed in thisapplication note. The remaining menu items that arenot discussed are the self-explanatory menus, such as File > Save and Help . The menus change slightlybetween the three software templates as Template MenusThe menu items for the Register template are shown inFigure 3. FIGURE 3:MENU BARThe three menus that are discussed are:VIEW MENUThis menu makes visible/invisible, the windows loadedin the Register MENUThis menu loads windows associated with the RegisterTe m p l a t e .OPTIONS MENUThe Options menu contains two sub-menu items that,as the name implies, sets options for the > - as shown in Figure 4 has autosaveoptions and numeric base settings.
10 The numeric basesettings select the default numeric base as displayed/entered in the windows. Selecting hexadecimal auto-matically places a $ in front of the entered numberindicating the number entered is :Selecting a window while holding down theshift key will load a copy of the window sothat more than one window of the sametype can be visible. This is useful foropening multiple Receive and Transmit windows for viewing multiple 4 2003 Microchip Technology 4:OPTIONS > > - as shown in Figure 5 sets theclock frequency, parallel port address, and whether theMCP2515 is reset on software clock frequency and parallel port address must beset properly for the software to function properly. TheMCP2515 clock frequency is used in calculating theCAN bus rate and is therefore required to be set.