您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > AT91M63200 I2C Drivers for AT24C512
1AT91M63200:I2CDriversforAT24C512SerialEEPROMIntroductionTheInterIntegratedCircuitBus(I²CBus)isasimplebi-directional2-wire,SerialData(SDA)andSerialClock(SCL)Busforinter-ICcontrol.TheAT91M63200doesnothavededicatedhardwaretomanageanI²Cline,butbecauseofitshighprocessingspeed,flexibleTimer/Counters(TC)andefficientinter-ruptmanagement,aneffectivesoftwareimplementationcaneasilybedone.ThisApplicationNotedescribessuchanimplementationcompliantwithARMprocedurecallstandard(APCS).ItisintendedforusewithanAT24C512serialEEPROM.TheoryofOperationTheindustry-standardinterfacedefinedbyI²Cconsistsofthefollowingsignals:GND:commonreferenceVCC:powersupplySCL:serialclocks.ThepositiveedgeoftheSCLinputisusedtoclockdataintotheEEPROMdeviceandthenegativeedgeclocksdataoutofthedevice.SDA:serialdata.TheSDApinisbi-directionalforserialdatatransfer.WaveformsFigure1.ClockandDataTransition:DataStableDataStableSCLSDADataChangeAT91ARM®Thumb®MicrocontrollersApplicationNoteRev.1742A–06/012AT91ARMThumb1742A–06/01Figure2.StartandStopConditionFigure3.AcknowledgeFigure4.WriteOperationFigure5.ReadOperationSCLSDAStartStopAcknowledgeStartDataInSCL189SDADataOutData[n+z]Data[n]SecondWordAddress=nFirstWordAddress=nDeviceAddressSDALine0MSBMSBLSBLSBR/WACKACKACKACKACKStopWriteStartStopWriteStartStartReadN0ACKACKACKACKR/WLSBLSBMSB00MSBLSBR/WDummyWriteSDALineDeviceAddressDeviceAddress1st,2ndWordAddress=nData[n]3AT91ARMThumb1742A–06/01AT91M63200ImplementationThisapplicationnotedescribeshowtoimplementaI²CmasterdeviceusinganAT91M63200IC.ATimer/CounterchannelandtwoPIOlinesareusedtomanagetheSCLandSDAlines.ThebytesfromtheEEPROMarestoredinareceptionbuffer.Thewritablebytescomefromatransmissionbuffer.TheTimer/Counterisclockedfromitsinternalclock(MCK/2).ThebitdurationandsamplingaregeneratedbyprogramingtheregisterC(RC):TheRCissetwiththebittimevalue.Inreadandwritemode,thecounterisresetateachRCCompareevent.ConnectionAtreset,allPIOpinsoftheAT91M63200areprogrammedasinputs.Therefore,theSDAlinemustbeconnectedtothesupplyvoltageviaapull-upresistor.(RefertothedatasheetoftheAT91M63200togetmoredetailsconcerningthevalueofthepull-upresistors.)Figure6.HardwareConnectionSourceFilesThefollowingsourcefilesareprovidedtoimplementtheAT91M63200I2CDriver:Table1.PeripheralDriversForeachperipheralused(Timer/Counter,advancedinterruptcontroller,etc.),astructureisdefinedtoprovideeasyaccesstotheperipheralregisters.Constantsarealsodefinedtopro-videeasyaccesstotheregisterfields.Theseperipheralsandconstantsaredefinedinlib_m63200.hVccPullupPIOiPIOjSDASCLAT91M63200EEPROMAT24C512FilesContentsstdio.hStandardCI/Odefinitionslib_m63200.hAT91M63200Libraryincludefilereg_m63200.hAT91M63200Registersincludefilelib_i2c.hI²Clinetypesandconstantslib_i2c.cTransmission/Receptioninterrupthandlerstest_i2c.cI²CEEPROMdriversi2c_irq.sAssemblerInterrupthandler4AT91ARMThumb1742A–06/01GlobalVariablesGlobalvariablesrelativetotheI²Clinearegroupedinastructure(I2Cdesc),typedefinedinlib_i2c.h,aportionofwhichisreproducedbelow.ExtractFromlib_i2c.hThisstructuregroupstimercharacteristics,PIOcharacteristics,bufferpointers,workingvari-ablesandinterrupthandleraddresses(AIChandlerandChandler).typedefstructI2C{//*Buffersu_char*RxBase;u_char*RxPtr;u_char*RxEnd;u_char*TxPtr;u_char*TxEnd;//*workvariablesu_chardeviceAddress;u_shortloadAddress;u_charnb_ACK;u_intnbI2CByte;u_charmode;signedcharcountBit;u_charI2CByte;u_charstate;//*PIOfieldStructPIO*pioa_base;constPioCtrlDesc*pio_ctrl_desc;u_intSDA;u_intSCL;//*TimerCounterfieldStructTCBlock*TCBase;StructTC*timerBase;u_charchannelId;//*IRQfieldTypeAICHandler*AICHandler;void(*I2CTCHandler)(structI2C*);}I2Cdesc;Note:Thetest_i2cfiledefinesastructureinstancefortheI²Cline:I2C_lineThelib_i2c.cfileusesapointertothisstructure(I2C_pt)toallowanaccesstothesevariables.5AT91ARMThumb1742A–06/01InterruptManagementReadandwritecommandsareimplementedbyinterupts.Theinitializationrelativetotheseinterrupts(stack,etc.)isnotdescribedinthisdocument,butinitializationmustbedonebeforeusingfunctionsdefinedinthisapplicationnote.TheAdvancedInterruptController(AIC)SourceVectorRegister(SVR)ofthetimerusedisfilledwithanassemblerinterrupthandler.Thisassemblerhandler(definedinI2c_irq.s)executesthebasicinterrupttreatments(reg-istersavingandrestoring,stackmanagement,endofinterruptacknowledgment,etc.)ThehandlerloadsthevariablestructurecorrespondingtotheI2Clinedescriptor(seeGlobalVariablessection)andcalltheI2C_lineHandlerIntChandlerwiththisstructureasaparameter.I2C_lineHandlerIntperformsthebasicoperationstobedoneforallhandlers:Readtimerstatustoacknowledgeinterrupt.CalltheChandlerdefinedbythevariableI2CTCHandlerfield.Thishandlerwillperformspecificoperationsaccordingtothemachinestate.Begin|Acknowledgeinterruptstatus|Callhandlerfollowingthemachinestate|EndI2CDriversTheI²Cdrivershavebeendesignedtosupportmulti-bytesequentialreadandwriteoperations.Awriteoperationrequiresthedeviceaddresswordandacknowledgment,followedbytwo8-bitdatawordaddresses,followedbythedatasequence.Thesequencemustbeginwithastartconditionandterminatewithastopcondition.Fi
本文标题:AT91M63200 I2C Drivers for AT24C512
链接地址:https://www.777doc.com/doc-3153400 .html