Vous êtes sur la page 1sur 9

18/3/2015

CANBUSShieldWiki

CANBUSShield
FromWiki
[
(http://www.seeedstudio.com/wiki/index.php?
title=CANBUS_Shield_&uselang=zh)]

Contents
1Introduction
2Specifications
3Demonstration
4Reference
4.11.SettheBaudRate
4.22.SetReceiveMaskand
Filter
4.33.CheckReceive
4.44.GetCANID
4.55.SendData
4.66.ReceiveData
5FAQ
5.1HowtoChangeSSPin
5.2CANBUSShieldinitfail
5.3HowtoCompatibleWith
ArduinoMegaandLeonardo
5.4Howtoremovetheterminal
resistor
6Resources

Introduction
CANBUSisacommonindustrialbusbecauseofitslongtraveldistance,mediumcommunicationspeedandhigh
reliability.Itiscommonlyfoundonmodernmachinetoolsandasanautomotivediagnosticbus.ThisCANBUS
ShieldadoptsMCP2515CANBuscontrollerwithSPIinterfaceandMCP2551CANtransceivertogiveyour
Arduino/SeeeduinoCANBUScapibility.WithanOBDIIconvertercableaddedonandtheOBDIIlibrary
imported,youarereadytobuildanonboarddiagnosticdeviceordatalogger.
ImplementsCANV2.0Batupto1Mb/s
SPIInterfaceupto10MHz
Standard(11bit)andextended(29bit)dataandremoteframes
Tworeceivebufferswithprioritizedmessagestorage
Industrialstandard9pinsubDconnector
TwoLEDindicators
Note:TheLibraryhadbeenupdatetoversion1.2inJuly8,2014

Specifications
http://www.seeedstudio.com/wiki/CANBUS_Shield

1/9

18/3/2015

CANBUSShieldWiki

Voltage5V
Dimensions68x53mm
NetWeight50g

Note:
WhenyouusemorethantwoCANBusShieldinonenet,youshouldconcernabouttheimpedance.
YoucanjustcutP1inthePCBwithaknife,orjustremoveR3onthePCB.

Demonstration

http://www.seeedstudio.com/wiki/CANBUS_Shield

2/9

18/3/2015

CANBUSShieldWiki

1.DownloadtheCANBUSSourcecodefileforArduino1.0(https://github.com/SeeedStudio/CAN_BUS_Shield)
andreleaseitinthelibrariesfileintheArduino1.0program.:..\arduino1.0\libraries.
Ifthefoldernameinclude"master",justremoveit.
2.OpentheArduino1.0,andyouwillfind3examples:receive_check,sendandreceive_interrupt.Herewe'lluse
sendandreceive_check,openitthenyoushouldgettwoprogrammingwindowsnow.

http://www.seeedstudio.com/wiki/CANBUS_Shield

3/9

18/3/2015

CANBUSShieldWiki

3.Uploadtwoexamplestotwoboardsseparately.Choosetheboardviathepath:Tools>SerialPort>COMX.
Notedownwhichboardisassignedasa"send"nodeandwhichboardisassignedasa"receive"node.
4.Openthe"SerialMonitor"onthe"receive"COM,youwillgetmessagesentfromthe"send"node.Herewehave
thepresetmessage"01234567"showinginthefollowingpicture.

Reference
http://www.seeedstudio.com/wiki/CANBUS_Shield

4/9

18/3/2015

CANBUSShieldWiki

1.SettheBaudRate
ThisfunctionisusedtoinitializethebaudrateoftheCANBussystem.
Theavailablebaudratesarelistedasfollws:
CAN_5KBPS,CAN_10KBPS,CAN_20KBPS,CAN_40KBPS,CAN_50KBPS,CAN_80KBPS,CAN_100KBPS,
CAN_125KBPS,CAN_200KBPS,CAN_250KBPS,CAN_500KBPSandCAN_1000KBPS

2.SetReceiveMaskandFilter
Thereare2receivemaskregistersand5filterregistersonthecontrollerchipthatguaranteeyougetdatafromthe
targetdevice.Theyareusefulespeciallyinalargenetworkconsistingofnumerousnodes.
Weprovidetwofunctionsforyoutoutilizethesemaskandfilterregisters.Theyare:
init_Mask(unsignedcharnum,unsignedcharext,unsignedcharulData)&init_Filt(unsignedcharnum,unsigned
charext,unsignedcharulData)
"num"representswhichregistertouse.Youcanfill0or1formaskand0to5forfilter.
"ext"representsthestatusoftheframe.0meansit'samaskorfilterforastandardframe.1meansit'sforaextended
frame.
"ulData"representsthecontentofthemaskoffilter.

3.CheckReceive
TheMCP2515canoperateineitherapolledmode,wherethesoftwarechecksforareceivedframe,orusing
additionalpinstosignalthataframehasbeenreceivedortransmitcompleted.Usethefollowingfunctiontopollfor
receivedframes.
INT8UMCP_CAN::checkReceive(void)
Thefunctionwillreturn1ifaframearrives,and0ifnothingarrives.

4.GetCANID
Whensomedataarrive,youcanusethefollowingfunctiontogettheCANIDofthe"send"node.
INT32UMCP_CAN::getCanId(void)

5.SendData
CAN.sendMsgBuf(INT8Uid,INT8Uext,INT8Ulen,data_buf)
isafunctiontosenddataontothebus.Inwhich:
"id"representswherethedatacomefrom.
"ext"representsthestatusoftheframe.'0'meansstandardframe.'1'meansextendedframe.
"len"representsthelengthofthisframe.
"data_buf"isthecontentofthismessage.
Forexample,Inthe'send'example,wehave:

http://www.seeedstudio.com/wiki/CANBUS_Shield

5/9

18/3/2015

CANBUSShieldWiki

unsignedcharstmp[8]={0,1,2,3,4,5,6,7};
CAN.sendMsgBuf(0x00,0,8,stmp);//sendoutthemessage'stmp'tothebusandtellotherdevicesthisisastandardframefrom0x00.

6.ReceiveData
Thefollowingfunctionisusedtoreceivedataonthe'receive'node:
CAN.readMsgBuf(unsignedcharlen,unsignedcharbuf)
Inconditionsthatmasksandfiltershavebeenset.Thisfunctioncanonlygetframesthatmeettherequirementsof
masksandfilters.
"len"representsthedatalength.
"buf"iswhereyoustorethedata.

FAQ
HowtoChangeSSPin
TheSPISSpinisdefaultD10,youcanchangeittoD9easily.
Firstly,cutoffthecopperwirebetweenCSanddigital10viaaknife,thendosomesolderingjustlikethefollowing
image

TOP

http://www.seeedstudio.com/wiki/CANBUS_Shield

6/9

18/3/2015

CANBUSShieldWiki

Then,youneedtochangetheSSPininthelibrary.
Youcanrefertohere(http://www.seeedstudio.com/forum/viewtopic.php?f=23&t=5231)

CANBUSShieldinitfail
AsfromCANBUSshieldV1.1tolatestversion,wechangedCSpinfromD10toD9bydefault.
Sopleasedothismodification"MCP_CANCAN(9)//SetCStopin9
"intheexample.

HowtoCompatibleWithArduinoMegaandLeonardo
Intheoldversion(thisbughadbeenfixedonversion1.1)ofCANBUSShield,SPIpinonlyconnecttoD11~D13.
ForArduinoUNO(Seeeduino),itworksfine.
ButforMegaandLeonardo,itdoesn'twork,becauseSPIpinofthoseboardwasnoD11~D12,soyouneedtoso
somehack.
Justasfollowing:

http://www.seeedstudio.com/wiki/CANBUS_Shield

7/9

18/3/2015

CANBUSShieldWiki

Moredetailsrefertohere(http://www.seeedstudio.com/forum/viewtopic.php?f=23&t=5172)
GoodnewsisthatanewversionofCANBUSShieldwillcomesoon,theSPIpinwillconnecttoICSP,itcaneasily
compatiblewithMega(Leonardo).

Howtoremovetheterminalresistor
There'sa62Ohm(120Ohminversion1.1hardware)onCANBUSShield.Sometimeit'snotneed.Youcanremove
iteasily,justasfollow:

http://www.seeedstudio.com/wiki/CANBUS_Shield

8/9

18/3/2015

CANBUSShieldWiki

Resources
CANBUSShieldSchematic.pdf(http://www.seeedstudio.com/wiki/images/7/78/CAN
BUS_Shield_v0.9b.pdf)
CANBUSShieldeaglefile(http://www.seeedstudio.com/wiki/images/7/75/CAN
BUS_Shield_v0.9b_20120621.zip)
CANBUSSourcecodefileforArduino1.0(https://github.com/SeeedStudio/CAN_BUS_Shield)
MCP2515datasheet(http://www.seeedstudio.com/wiki/images/8/83/MCP2515.pdf)
MCP2551datasheet(http://www.seeedstudio.com/wiki/images/8/8c/Mcp2551en.pdf)
Retrievedfrom"http://www.seeedstudio.com/wiki/index.php?title=CANBUS_Shield&oldid=103694"
Thispagewaslastmodifiedon10February2015,at08:04.
Thispagehasbeenaccessed132,549times.

http://www.seeedstudio.com/wiki/CANBUS_Shield

9/9

Vous aimerez peut-être aussi