Example: bachelor of science

Programming Examples for the TMS320x28xx …

1 SPRA876B January2003 RevisedSeptember2017 SubmitDocumentationFeedbackCopyright 2003 2017,TexasInstrumentsIncorporatedProgram mingExamplesfor the TMS320x28xxeCANA pplicationReportSPRA876B January2003 RevisedSeptember2017 ProgrammingExamplesfor the C2000 MicrocontrollerABSTRACTTheTMS320x28xxser iesof Microcontrollers/DigitalSignalController sfeaturean on-chipenhancedControllerAreaNetwork(eCA N) a full-CANcontroller, applicationreportcontainsseveralprogramm ingexamples,supplementalto thosein C2000 Ware/controlSUITE,to illustratehow the eCANmoduleis set up for differentmodesof objectiveis to help you comeup to speedquicklyin programmingthe programshavebeenextensivelycommentedto aid a TMS320F28335device;however,the examplescan be easilyadaptedto run on any C2000devicethat featuresthe the examplesneedCAN-B(the secondCANnode)for partsthat haveonlyone CANmodule(CAN-A),a second(external)CANnodeis neededto emulatethe functionof be met by anyCANbus analysistoolsare the CANbus trafficand are also capableof generatingCANbus framesandarean invaluableaid in oscilloscopewithbuilt-inCANbustriggering /decodingis a vital debuggingaid as are availablefor downloadfromthe followingURL: DesignTips to trademarksare the propertyof a multi-masterserialprotocolthat was originallydevelopedfor to itsrobustnessand reliability,it now findsapplicationsin diverseareassuchas Industrialautomation,appliances,medicale lectronics,maritimeelectro

Debug and Design Tips to Resolve/Avoid CAN Communication Issues www.ti.com 4 SPRA876B–January 2003–Revised September 2017 Submit Documentation Feedback

Tags:

  Programming, Example, Programming examples for the tms320x28xx, Tms320x28xx

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Programming Examples for the TMS320x28xx …

1 1 SPRA876B January2003 RevisedSeptember2017 SubmitDocumentationFeedbackCopyright 2003 2017,TexasInstrumentsIncorporatedProgram mingExamplesfor the TMS320x28xxeCANA pplicationReportSPRA876B January2003 RevisedSeptember2017 ProgrammingExamplesfor the C2000 MicrocontrollerABSTRACTTheTMS320x28xxser iesof Microcontrollers/DigitalSignalController sfeaturean on-chipenhancedControllerAreaNetwork(eCA N) a full-CANcontroller, applicationreportcontainsseveralprogramm ingexamples,supplementalto thosein C2000 Ware/controlSUITE,to illustratehow the eCANmoduleis set up for differentmodesof objectiveis to help you comeup to speedquicklyin programmingthe programshavebeenextensivelycommentedto aid a TMS320F28335device;however,the examplescan be easilyadaptedto run on any C2000devicethat featuresthe the examplesneedCAN-B(the secondCANnode)for partsthat haveonlyone CANmodule(CAN-A),a second(external)CANnodeis neededto emulatethe functionof be met by anyCANbus analysistoolsare the CANbus trafficand are also capableof generatingCANbus framesandarean invaluableaid in oscilloscopewithbuilt-inCANbustriggering /decodingis a vital debuggingaid as are availablefor downloadfromthe followingURL.

2 DesignTips to trademarksare the propertyof a multi-masterserialprotocolthat was originallydevelopedfor to itsrobustnessand reliability,it now findsapplicationsin diverseareassuchas Industrialautomation,appliances,medicale lectronics,maritimeelectronics,and so (andisolation)mechanismsand lendsitselfto simplewiringat the showsthe typicalimplementationof the Bus -LineRLCANC ontroller(Node #1)DSP or C CANT ransceiverCANC ontroller(Node #n)DSP or C CANT ransceiverCANC ontroller(Node #2)DSP or C CANT ransceiverCANC ontroller(Node #3)DSP or C January2003 RevisedSeptember2017 SubmitDocumentationFeedbackCopyright 2003 2017,TexasInstrumentsIncorporatedProgram mingExamplesfor the TMS320x28xxeCANF igure1. TypicalImplementationof a Full implementationof CANprotocol, 32 mailboxes,eachwith the followingproperties: Configurableas receiveor transmit Configurablewith standardor extendedidentifier Has a programmablereceivemask(everymailboxhas its own mask) Supportsdataand remoteframe Composedof 0 to 8 bytesof data Usesa 32-bittime stampon receiveand transmitmessage Protectsagainstreceptionof new message Holdsthe dynamicallyprogrammablepriorityof transmitmessage Employsa programmableinterruptschemewith two interruptlevels Employsa programmablealarmon transmissionor receptiontime-out Low-powermode Programmablewake-upon bus activity Automaticreplyto a remoterequestmessage Automaticretransmissionof a framein caseof loss of arbitrationor error 32-bitTimeStampCounter(TSC),whichcan be synchronizedby a specificmailbox2 ProgramsThe exampleprojectsare meantto run seamlesslywheninstalledin the runningthe exampleson a 2833x/2832xtarget,unzipthe files inC.

3 \ti\c2000\C2000 Ware_1_00_01_00\device_support\f2833x\ othertargetdevices,the targetdirectoryand supportfiles needto be modified. CAN_MBXRAMRWThis exampleperformsrepeatedwritesand readsto the exercisesthe mailboxRAMheavily,it may also be usedto checkthe correctfunctionalityof the mailboxRAMbits. CAN_TXLOOPThis programtransmitsdatato transmitloop can be executedapredeterminednumberof timesor checkthe DesignTips to Resolve/AvoidCANC ommunicationIssues3 SPRA876B January2003 RevisedSeptember2017 SubmitDocumentationFeedbackCopyright 2003 2017,TexasInstrumentsIncorporatedProgram mingExamplesfor the TMS320x28xxeCAN CAN_RXLOOPThis is an exampleof how datamay be receivedusingpolling. CAN_RXINTThis is a simpleexampleof how datamay be also illustratesthe abilityofthe CANmoduleto servicemultipleinterruptsautomatically. CAN_ECHO-ABCAN-Atransmitsto CAN-B,whichthenechoesthe databackto examplecan be usedto checkcommunicationbetweenCAN-Aand the DSPneedto be connectedto eachother(via CANtransceivers).

4 CAN_DBOTXI llustratesthe operationof DBOfield for a Transmitmailbox. CAN_DLCTXI llustratesthe operationof DLCfield for a Transmitmailbox. CAN_MBXWDIFThis codeillustratesthe functionalityof the WDIF nbit (WDIF-WriteDeniedInterruptFlag). CAN_MOTOThis exampleillustratesthe MessageObjectTimeOut (MOTO) feature. CAN_MULTINTThis exampleillustratesthe abilityof the CANmoduleto ,this exampleshowshow whenan interruptflag is set whileanotherinterruptflag is alreadyset, the mostrecentinterruptflag automaticallygeneratesa corelevelinterruptuponexitingthe ISR ofthe previousinterrupt. CAN_RXMSGLSTThis exampleillustrateshow contentsof a mailboxcan be protectedfrombeingoverwrittenby usingthe OverwriteProtectionControl(OPC) bit. CAN_TCOFThis exampleillustratesthe functionalityof the TimerCounterOverflowFlag(TCOF) bit. CAN_TRPRTSTPThis programillustratesthe programmabletransmit-priorityand time stampingfeature. CAN_TXABORTC hecksthe transmitabortoperationusingthe TRRbit.

5 Transmitabortoperationusingthe TRRbit. CAN_LPMwakeupThis exampleillustratesthe abilityof the CANmoduleto enterand exit low-powermode(LPM).Notethat this low-power-modeis localto the CANmoduleand shouldnot be confusedwith the device-levellow-power-modeslike HALT,STANDBYand IDLE. CAN_REMOTE_frThis exampleillustratesthe abilityof the CANmoduleto SEND remoteframesfrom(andreceivedataframesin) the sameMailbox. CAN_LAMI llustrateshow AcceptanceMaskFilteringworksusingCANLAM registers. CAN_jigA usefultest-jigfor debuggingCANbus Transmit/ReceiveStandardand Extendedframesat transmitting(andrespondingto) optionsareselectedusingGPIO0-GPIO3or througha hard-codedvaluein the DesignTipsto Resolve/AvoidCANC ommunicationIssuesThis sectionillustratessomeof the commonmistakesand oversightspeoplenew to the CANprotocoltendto makewhileimplementinga CANbus. This is followedby somedebuggingtips usefultotroubleshootbus DesignTips to January2003 RevisedSeptember2017 SubmitDocumentationFeedbackCopyright 2003 2017,TexasInstrumentsIncorporatedProgram mingExamplesfor the NodesRequiredUnlessworkingin the self-testmode,a minimumof two nodesare neededon the CANbus for thefollowingreason:Whena nodetransmitsa frameon the CANbus, it expectsan acknowledgment(ACK)fromat leastone othernodeon the time a CANnodesuccessfullyreceivesa messageit willautomaticallytransmitan ACK,unlessthat featurehas beenturnedoff (someCANimplementationsfeaturea so-called"silentmode",wherea nodereceivesthe frame,but doesnot providean ACK;theDCAN modulein TMS320F2837xxseriesMCUsfromTI has this feature).

6 The nodethat providesthe ACKdoesnot needto be the intendedrecipientof the frame,althoughit couldvery well be. (All activenodeson the bus will providean ACK,regardlessof whetherthey are the intendedrecipientsof that frameornot).Whenthe transmittingnodedoesnot receivean ACK,it resultsin an ACKerrorand the transmittingnodekeepsre-transmittingthe TransmitErrorCounter(TEC)will incrementto 128 and 0. Nodewill not go this situation,the TA bit for the transmittingmailboxdoesnot get set. No interruptswill be anothernodeis broughtinto the network,theTECwill startdecrementing(all the way to 0) with Transceiveris NeededOne cannotdirectlyconnectCANTXof node-Ato CANRXof node-Band vice versaand this case,CANis unlikeotherserialinterfaceslike SCI or SPI. For example ,SCIcan be madeto workwith a RS232transceiveror througha directconnection(SCITXof one nodetoSCIRXof anothernodeand vice versa).However,CANbus needsa CANtransceiverfor the followingreason:In additionto convertingthe single-endedCANsignalfor differentialtransmission,the transceiveralso loopsbackthe CANTXpin to the CANRXpin of a is becausea CANnodeneedsto beable to monitorits own This has to do with the ACKrequirementmandatedby the nodetransmitsaframeon the CANbus, it expectsan ACKfromat leastone othernodeon the the ACKphase,the transmitterputs out a 1 and expectsto readbacka 0.

7 Duringarbitration,a nodewith a higher-priorityMSGID needsto be able to overridea 1 with a 0. Hereagain,the transmitterneedsto be able to readbackthe nodeputs out a 1and readsbacka 0 duringthe arbitrationphase,it sectionhighlightssomecommonmistakesin the designand implementationof a CANbus Is clockto the CANmoduleenabled?Checkfor this if writesto CANregistersare not enabledthrougha bit in the PCLKCR nregister. Are 32-bitR/Woperationsusedwhileaccessingthe eCANregisters?For an example ,see the device-specificTRM. Commentall EDIS fromyourcodeuntil you get it to couldadd it are EALLOW protectedand a writemay not go throughif EALLOWis not active. Try yourcodewithoutinterruptsfirst. Use ,you can add interruptslater. If a specificmailboxis not working,haveyou attemptedto use a differentmailbox?Havethe mailboxesbeenenabledin the CANME registerand the mailboxdirectioncorrectlyconfiguredin the CANMD register? Wasthe MSGGID registerinitializedto zero,beforethe individualbits/Bit-fieldswereconfigured?

8 Watchout for bits that may comeup undefineduponreset. Do not use addedlateronceit is confirmedthereare no hardwareissueswith the January2003 RevisedSeptember2017 SubmitDocumentationFeedbackCopyright 2003 2017,TexasInstrumentsIncorporatedProgram mingExamplesfor the Has the bus beenterminatedcorrectly(with120- ) at eitherends(only)?The bus mustbe terminatedonly at eitherendsand with a 120- otherwords,no morethantwo terminatorresistorsmay be presenton the bus, unlesssplit terminationis followed,in whichcasetherewill be tworesistorson CANbus system,it is importantthat the terminationresistorscan be enabled/disabledfromoutsidethe schememakesit easywhennodeshaveto be added/removedto/fromthe network. Are all CANnodesconfiguredfor the samebit-rate?Mis-matchednodebit rateswouldrepeatedlyintroduceerrorframes on the bus. Capturethe outputof a nodeon the oscilloscopeto physicallyverifythe bit-time. Haveyou trieda lowerbit-rate?Say,50 kbps,for example ?

9 Timingissuesconcerningpropagationdelaysm ay be caughttryinga CANBTR registerhas the programmedvalue. For deviceswith an on-chipzero-pinoscillator(INTOSCn), are you usingan externalclocksourceorthe INTOSCn?If you are usingINTOSCn,do you performtemperaturecompensationof INTOSCn(fordeviceswheretemperaturecompen sationis allowed)? Haveyou triedto reducethe bus lengthand numberof nodes? Beforethe occurrenceof the errorcondition,wereany error-framesseenon the bus?This couldpointto timingviolationsor noiseissues. Howmanynodesare therein the bus?(In non-self-testmode,theremustbe at leasttwo nodeson thenetwork,due to the acknowledge(ACK)requirementmandatedby the CANprotocol) To see the waveformuntil the ACKphase,a transceivermustbe connectedto the ,the nodeimmediatelygoesinto an errorstate. Checkif the CANframeis correctlyseenat the CANRXpin of the MCUand it is of the expectedbit-rate. If usingan oscilloscopewith a built-inCANtrigger,makesurethat the signalconfiguredfor triggeringmatchesthe signalbeingprobedon the capableof triggeringon CAN-transmit(CANTX),CAN-receive(CANRX),C AN_Hand CAN_Lsignals,in additionto Start-of_Frame(SOF),Remoteframes,Errorfr amesand Introductionto the ControllerAreaNetwork(CAN) ControllerAreaNetworkPhysicalLayerRequir ements Basicsof Debuggingthe ControllerAreaNetwork(CAN)PhysicalLayer Calculatorfor CANBit TimingParameters Overviewof (ControllerAreaNetwork)Transceivers SimplifyCANBus ImplementationsWithChokelessTransceivers CriticalSpacingof CANBus Connections ImprovedCANN etworkSecuritywith TI s SN65 HVD1050 Transceiver MessagePriorityInversionon a CANBus PiccoloMCUCANM oduleOperationUsingthe January2003 RevisedSeptember2017 SubmitDocumentationFeedbackCopyright 2003 2017,TexasInstrumentsIncorporatedRevisio nHistoryRevisionHistoryNOTE.

10 Pagenumbersfor previousrevisionsmay differfrompagenumbersin the Revision(April2003)to B Title of the documenthas Abstracthas Updatewas madein ' ' sectionwas Updatesweremadeto Updatesweremadeto ( TI ) technical,applicationor otherdesignadvice,servicesor information,including,but not limitedto,referencedesignsand materialsrelatingto evaluationmodules,(collectively, TI Resources ) are intendedto assistdesignerswho aredevelopingapplicationsthat incorporateTI products;by downloading,accessingor usingany particularTI Resourcein any way,you(individuallyor, if you are actingon behalfof a company,yourcompany)agreeto use it solelyfor this purposeand subjectto the termsofthis s provisionof TI Resourcesdoesnot expandor otherwisealterTI s applicablepublishedwarrantiesor warrantydisclaimersfor TIproducts,and no additionalobligationsor liabilitiesarisefromTI providingsuchTI reservesthe rightto makecorrections,enhancements,improvement sand otherchangesto its TI understandand agreethat you remainresponsiblefor usingyourindependentanalysis,evaluationa nd judgmentin designingyourapplicationsand that you havefull and exclusiveresponsibilityto assurethe safetyof yourapplicationsand complianceof yourapplications(andof all TI productsusedin or for yourapplications)with all applicableregulations,lawsand ,with respectto yourapplications,you haveall the necessaryexpertiseto createand implementsafeguardsthat (1)