TI德州仪器电池电量计单线协议HDQ应用.doc_第1页
TI德州仪器电池电量计单线协议HDQ应用.doc_第2页
TI德州仪器电池电量计单线协议HDQ应用.doc_第3页
TI德州仪器电池电量计单线协议HDQ应用.doc_第4页
TI德州仪器电池电量计单线协议HDQ应用.doc_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

TI德州仪器电池电量计单线协议HDQ应用 Application ReportSLAA196FebruaryxxHDQ ProtocolImplementation withMSP430Andreas DannenbergMSP430Introduction Mostbattery monitorICs from TI,such as the bq2019and bq26500,include asingle-wire serialdata interface(HDQ bus).Host controllerscan usethis interfaceto aessvarious on-chip registersto read-out batterycapacity,voltage,and otherparameters.The purposeof this application noteis topresent asolution forinterfacing HDQ-enabled battery gas gaugedevices with the MSP430microcontroller family.HDQ BasicsThe HDQ bus isa master-slave bussystem usinga simpleone-wire,asynchronous,bi-directional,serial interfacewith abit-rate of about5-Kbit/s.The bus line isdriven byopen-collector devicesand thereforerequires anexternal pull-up resistor.The relativelyslow bitrate issufficient for reading outas wellas settingregisters inbattery monitorICs.The hostmay onlyneed tomunicate atinfrequent intervalsto updatethe userwiththelatest runtimeputation,thus minimizingmunication andsaving power.Data isalways transmittedbit-by-bit inblocks of8-bits withthe LSBfirst.The bitsare encodedas shown in Figure1.Every bitalways startswith ahigh-to-low transitionof the HDQ bus line.The signalreturns to high after time t1if the bit isa oneand returnstohighaftertimet0if thebit isa zero.The bitcycle timet CYCis typicalin therange of190?s.Please seethe datasheetof an HDQ enabledgas gaugedevice for the exacttiming specifications1.Figure1.HDQ BitTiming10t1t0t CYCThe protocolis mand-based anddata istransferred inblocks of2bytes.The firstbyte isalways sentby the host(master)and contains the clientregister address(7-bit).It alsocontainsthe R/W-bit,which determinesif the next byteis sendby hostto theclient(R/W=1)orreadfrom theclient bythehost(R/W=0).1SLAA196MSP430HDQ ImplementationThis sectiondescribes howan MSP430microcontroller can be interfacedwith HDQ-enabled devices.As anexample,the interfaceto the bq26500single-cell Li-Ion andLi-Pol batterygas-gauge ICis presented.The basicdemo applicationreads outthe on-chip temperaturesensor andprovides feedbackabout temperaturechanges usingan LED.Hardware DescriptionFigure2shows atypical HDQsystem consistingof anMSP430F1101used asa hostcontroller anda bq26500gas-gauge ICused asa slave device.The selectedMSP430device isa20-pin,low-cost MSP430family member.More information on thisdevice can be foundin the device data sheet2.Any otherMSP430derivates could be usedif morefunctionality isrequired onthe applicationside.Figure2.MSP430HDQ ExampleSchematic3VMSP430F1101VCC3Vbq26500VCC3V0.1?FRST10K330R100KP1.1/TA0HDQR OSCVSS VSSGPIO Togenerate the HDQ bustiming,the Timer_A moduleof the MSP430is used.In particular,the capture/pare block0(CCR0)is used for generatingand samplingthe bussignals withhardware support.The associatedMSP430pin,TA0,is broughtout viaport pinP1.1and connected to the slave device.A10-kohm pull-up resistoris providedas the HDQ busis operated in high-impedance mode.Additionally,a100-kohm resistorbetween the MSP430R OSCpin andVCC is connectedtostabilize the internal DCOclock generator and achievea systemclock witha verylow temperatureand voltagedrift.However,in ausers application,other waysof providinga stableclock to theMSP430could beused such as anexternal32-kHz watchcrystal whichwould alsoenable theMSP430to implement an ultra-low-power real-time clockfunction.2HDQ ProtocolImplementation withMSP430SLAA196For demonstrationpurposes,the bq26500device is used asa LED-driver only.The GPIOpin isswitched tooutput directionand operatedas anopen-drain output.Basic HDQ munication functionalitycan nowbe shownusing thisLED.Please refer to the bq26500data sheetfor detailedapplication informationon using this batterygas-gauge IC1.Software DescriptionThe demonstrationsoftware forthis applicationreport consistsof themunication libraryHDQ.c/HDQ.h andan applicationusingthislibrary(bq26500_LED.c).The municationlibrary isalso providedin assemblylanguage withthe equivalentfunction(HDQ.s43).It makesuse of the sameC callingconventions asHDQ.c.By removingHDQ.c andadding HDQ.s43to theproject file,the assemblyversion of the codecan beused.Only oneof thesefiles mustbe includedin theproject,otherwise thebuild resultsin symbolconflicts.The Assemblyversion ISRis executedfaster(11%to48%,depending onthe function)than theC versioneven withthe highestoptimizer settings.This ismainly dueto theuse ofefficient calculatedbranches in the Assemblyinterrupt servicefunction opposedto thefull implementationof aC languageswitch/case statement.HDQ CommunicationLibrary Thislibrary offersplete municationto an HDQ enableddevice,such asthe bq26500batterygasgauge IC.The entirehost municationis implementedin softwareand issupported bythe Timer_A hardwaremodule thatcan befound onall MSP430devices.It alsouses interruptsand low-power modesto minimizecurrent consumption.Due to the Timer_A support,interrupt latencyintroduced byother interruptsthat arebeing servicedand areblocking theCPU is not critical.The Timer_A0_ISR()function mustbe servicedbefore the next captureor pare event ours.The softwarelibrary can be adaptedto meetthe requirementsofaparticular application.For example,the useris freeto selecta differentclock sourceor frequencyfor sourcingthe Timer_A module.In thiscase,the timing constants asdefined inthe header file mustto bemodified.For convenience,all thetimingconstantsused arederived fromone timerclock frequencydefinition ClkFreq.The entirebit timingcan bere-calculated bychanging thisdefinition.By addingeither theC(HDQ.c)or Assembly(HDQ.s43)code fileto theproject andincluding theheader fileHDQ.h into a program,the followingthree functionscanbecalled:void HDQSetup(void)Calling thisfunction performsa basicsetup andthat is needed for the datatransfer.It setsport pinP1.1used for the HDQbus lineconnection toinput andenables the Timer_A.CCR0function forthis pin.void HDQWrite(unsigned charAddr,unsigned charData)HDQ ProtocolImplementation withMSP4303SLAA196The HDQWrite()function isused towrite datatoadevice that isconnectedover theHDQbus.HDQ slave devices areusually internallyorganized asa blockof registers.The parameterAddr containsthe7-bit address(0127)of the register towrite to,and theData parameterthe8-bit datato transfer.After startingthe Timer_A module,anHDQbreak conditionis sentby callingthe localfunction HDQBreak().This isto ensurethat the slave deviceHDQ enginewill bereset forthe casethe chiphas alreadyseen astart ofmunication dueto contactbouncing duringbattery insertion.In thenext step,the7-bit registeraddress istransmitted to the slave device withthe R/W bitset toone.This willmake theslavedevicereceive thesecond byte(data byte)after ashort delay.The localfunction HDQBasicWrite()isusedfor sendingout datawords.Figure3shows howthe Timer_A isused togenerate theHDQ signalwaveform.The CCR0block isused inpare modeonly andsetup totoggle theHDQ signalon everypare event.An interruptis generatedfor eachpareevent.The ISRfunction incrementsthen theCCR0register bythe numberof timercounts untilthenextsignal transitionis needed.This way,bit-by-bit istransferred viatiming thatis hardwaregenerated.The countvalues thatdetermine thecycle time(bit time)and thepoint of the low-to-high transitionare alldefined inthe moduleheaderfile.Figure3.Transmit BitTiming Compare CompareCompare10On pletionof themunication the Timer_A moduleis disabledto conservepower.It canalso bere-configured atthis pointif requiredfor differentfunctions.Note thatby limitationsof theHDQ protocol(e.g.,pared toan I2C munication)it cannotbe determinedwhether theslavedevicehas receivedthe datasuessfully.unsigned intHDQRead(unsigned charAddr)4HDQ ProtocolImplementation withMSP430SLAA196Using thefunction forreading aregister issimilar totheregisterwrite aess.After sendinganHDQbreak condition,the addressAddr fortheslavedevice registerto beaessed issent outby callingthe localfunction HDQBasicWrite().By havingtheR/W bitintheaddress bytecleared,theslavedevice willstart transmittingthe contentsof theaddressed registerby pullinglow thenow high-impedance HDQbuslineaording totheHDQtiming specification.The Timer_A CCR0block isused incapture modeto waitforthefalling signaledge,and thenswitched overto pare mode.In paremode itlatches thestate of theHDQbuslineat thecenter of thebittimes forzero andone:t Sample=(t0+t1)/2using theSCCI latch.The SCCIlatch featureof the Timer_A avoidsthe latencyoftheCPU toexecute theISR.Please referto3for detailedinformationontheTimer_A operation.Figure4.Receive BitTiming CaptureCompare(Sets SCCILatch)10After eightbits havebeen read,theTimer_A moduleis disabledand thefunction willreturn theread-out value.To avoida potentialsoftware-lockup atthis point(forthe case thatno municationtotheslavedevicecanbeestablished),theTimer_A CCR1block isused inparemodeto providea time-out mechanism.It abortsthe receptionif nostart edgecould bereceived withint TO.In thiscase,the HDQRead()function willreturn0xffff toindicate theapplication that there was a municationfailure.This isa uniquevalue and will notour duringnormal munication.Application ExampleThe applicationexample is intended todemonstrate theusage oftheHDQmunication exampleand requiresthe hardwareshowninFigure2to function.One ofthe featuresofthe used bq26500gas-gauge ICis aninternal temperaturesensor thatcanberead outusing theHDQ interface.The temperatureis measuredperiodically andstored intothe internalon-chip registersTEMPH andTEMPL witha resolutionof0.25K.For adetailed descriptionofthe bq26500features pleaserefertothedevicedatasheet1.When the program bq26500_LED.c isexecuted,theMSP430will doan initial temperature read-out ofthebq26500IC andstore the result intothe localvariable FirstTEMPL.Prior tothe initialread-out,theprogramwill waitfor ashort durationto givethebq26500time todo itsfirst temperaturemeasurement andinitialize itsinternal registersproperly.This delayis onlyneeded inthecasethebq26500and theMSP430are poweredup atthe sametime asit isdone inthe example(Figure2).HDQ ProtocolImplementation withMSP4305SLAA196The temperatureis read-out periodicallyevery1s usingthe WDTand paredtotheinitialtemperaturevalue FirstTEMPL.If therewasachange intemperature ofat least1K(which equalsfour TEMPLcounts),the GPIOopen-drain outputofthebq26500is activatedand theconnected LEDwill illuminate.As soonasthetemperature returnstotheFirstTEMPL+/-1K window,the LEDwill beswitched off.The watchdog-timer isoperatedininterval modeandwillgenerate aninterrupt every32768SMCLK counts.As thisclock hasa frequencyof2MHz withtheusedoscillator configuration,the WDTinterrupt servicefunction iscalled every1/60th second.It decrementsa counterthatisused toimplementalow-power Delay()function.When thecounter decrementsto zero,the low-power modeLPM0is deactivatedand theprogram executionresumes withthenextinstruction afterthe Delay()function.The MSP430isinlow-power modeLPM0most ofthe time.This modehas beenchosen asit leavestheinternalDCO oscillatorrunning whichisneededin thissetup togenerate theinterval timingusedforHDQmunicationand alsofor sourcingthe WDT.Other low-power modessuchasLPM3that couldreduce thecurrent consumptionfurther requirean additionalexternal32-kHz watchcrystal.For everyHDQ readoperation thatis performed,theresultoftheHDQRead()function ispared with0xffff tocheck ifa time-out hasourred.In thiscase,the softwarewill proceedand readthe dataagain.Depending onthe usersapplication,an additionalerror messagecouldbegenerated.References1.bq26500Single-Cell Li-Ion andLi-Pol BatteryGas GaugeIC Data Sheet(SLUS567)2.MSP430C11x1,MSP430F11x1A MixedSignal MicrocontrollerDataSheet(SLAS241)3.MSP430x1xx FamilyUsers Guide(SLAU049)6HDQ ProtocolImplementation withMSP430IMPORTANT NOTICETexas Instruments Incorporatedand itssubsidiaries(TI)reserve theright tomake corrections,modifications,enhancements,improvements,and otherchanges toits products and servicesat anytime andto discontinueanyproduct orservice withoutnotice.Customers shouldobtain thelatest relevantinformation beforeplacingorders andshould verifythat such information iscurrent andplete.All productsare soldsubject toTIs termsandconditions of sale suppliedatthe time oforder acknowledgment.TI warrantsperformance ofits hardwareproducts tothe specificationsapplicable atthetimeofsaleinaordance withTIs standardwarranty.T estingand otherquality controltechniques areused tothe extentTIdeems necessaryto supportthis warranty.Except wheremandated bygovernment requirements,testing ofallparameters ofeach productisnotnecessarily performed.TI assumesno liabilityfor applicationsassistance orcustomer productdesign.Customers areresponsible fortheirproducts andapplications usingTI ponents.T ominimize therisks associatedwith customerproductsand applications,customers shouldprovide adequatedesign andoperating safeguards.TI doesnot warrantor representthat anylicense,either expressor implied,is grantedunder anyTI patentright,copyright,mask workright,or otherTI intellectual property rightrelating toany bination,machine,or processinwhich TI products or services areused.Information publishedby TIregarding third-party productsor servicesdoesnot constitutea license fromTIto usesuch productsor servicesor awarranty orendorsement

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论