Home
EFM32 Getting Started - AN0009 - Application Note - Digi-Key
Contents
1. 2 3 Access types Each register has a set access type for all of the bit fields within that register The access types describes the reaction to read or write operation to the bit field The different access types found for the registers in the EFM32 devices are found in Table 2 1 p 4 Table 2 1 Register Access Types Access Type Description Read only Writes are ignored RW Readable and writable RW1 Readable and writable Only writes to 1 have effect W1 Read value undefined Only writes to 1 have effect Ww Write only Read value undefined RWH Readable writable and updated by hardware 2 4 CMSIS and EFM32LIB The Cortex Microcontroller Software Interface Standard CMSIS is a common coding standard for all ARM Cortex devices The CMSIS library provided by Energy Micro contains header files defines for peripherals registers and bitfields and startup files for all EFM32 devices In addition CMSIS also includes functions which are common to all Cortex devices like interrupt handling etc Although it is possible to write to registers using hard coded address and data values it is recommended to use the defines to ensure portability and readability of the code To use these defines we must include efm32 h in our c file This is a common header file for all EFM32 devices Within this file the correct header file for the specific device is included according to the preprocessor symbols defined for your proje
2. an0009 Rev1 11 www energymicro com EFINT32 the world s most energy friendly microcontrollers 5 Example 2b Blinking LEDs with DK To run this example you need a Development Kit The aim is to use the GPIO pins to light up the LEDs on the DK and change the LED configuration every time the joystick is moved The efm32 workspace contains a project called kit name 2 leds which will be used in this example 5 1 Board Support Library The EFM32 Gecko Development Kit uses a board controller to configure the functions of the development kit including lighting the user leds and reading buttons joystick These functions can be controlled by the EFM32 by communicating with the board controller via either SPI or External Bus Interface The EFM32 can then configure the registers in the board controller to set up the functions wanted The EFM32 Board Support Library includes drivers for handing access to the DK An initialize function must be run first to configure either the EBI or the SPI connection void DVK init void Devices with LCD support will automatically be set up with SPI access while devices without LCD support will use EBI by default The yellow lights to the left of the MCU board on the DK will tell you which connection is active Note that the connection to the board controller will occupy the EBI or the USART2 SPI on your device as well as the pin connections for these These resources can not be used for other purposes
3. Information sic 20 B Contact InfOrmiatiori so saa asa aa aja AE a ED A KA ade anan aja a EE ian ada pa saa baa aaa TA aaa a aa panda D D aa a aaa naa 21 B 1 Energy Micro Corporate Headquarters aana aaa aane nett e teeter emen ee he he he ne ne nene nennen 21 B 2 Global Contacts mb m 21 2011 10 21 an0009 Revi 11 22 www energymicro com Er nNT32 the world s most energy friendly microcontrollers List of Figures Example register description o ecce ici ect eei Peur en e REOR SER E REFER EIER Ped eee ERR A ES ea ees EUNT eR MERE ete 4 Grouped registers in GPIO 0 00 EE hehe he he hi ee ne ne ne ne ne nene ne ne nnne nenne 7 Debug View in TAR ian c cU 9 Documentation for the CMU specific efm32lib functions aaa eaaa tn mme ene 10 CMU ClockEnable function description sssssssssssesss mmm eene ee ne ne ne nene nenne 11 KADIM ai OR FUNCTION RIETI RIT DET 14 2011 10 21 an0009 Rev1 11 www energymicro com EFMS3Z the world s most energy friendly microcontrollers List of Tables 2 1 Register Access TYPES LEE 4 2011 10 21 an0009_Rev1 11 www energymicro com EFMS3Z the world s most energy friendly microcontrollers List of Examples MEL sasae aana aa Aa E Sealed EN AA eee NDE ET ied gata Sede TETUA KA ETE Sed ended aa ga a eesti eed TENO ag aston ial 5 2 2 Defines for
4. REFRSEL bit field in DACn CTRL aaa eaaa cece nana eee eee meme anana aaa eaaa anana aana aana aana anana 5 2 3 Defines for LPFEN bit field in DACn GTRL 556 rai BN a aga a eee eee a mm RENA AR GAE AGA SADE KANEA E KA GA rennen 6 www energymicro com 2011 10 21 an0009_Rev1 11 EFIM3s2 the world s most energy friendly microcontrollers List of Equations 2 1 Register address calculated from base and offset eee cece ee eee e ee eee ee ees eeeeseeeeeaeeeeeseeeeeseeeeeaeeeeeneeeeed 3 2011 10 21 an0009 Rev1 11 www energymicro com ENERGY micro Energy Micro AS Sandakerveien 118 P O Box 4633 Nydalen N 0405 Oslo Norway www energymicro com
5. is pressed Instead of accessing the registers directly we will use the efm32lib functions to configure the peripherals The efm32 workspace contains a project called lt kit_name gt _2_leds which will be used in this example The efm32lib C files are included in the project The corresponding header files are included at the beginning of the C files For details on which efm32lib functions exist and how to use them we will open up CMSIS Documentation through Simplicity Studio After clicking on the efm32lib link for the correct EFM32 series Gecko Tiny Gecko etc we open up Modules EFMS32 Library and select the CMU peripheral Scrolling down we find a list of functions Figure 4 1 p 10 that we can use to to easily operate the Clock Management Unit Figure 4 1 Documentation for the CMU specific efm32lib functions 3e Q7 Functions EFNT32 CMU ClockEnable CMU Clock TypeDef clock bool enable Energy Micro EFM32LIB Enable disable a clock EH Modules CMU ClockFreqGet CMU Clock TypeDef clock Get clock frequency for a clock point EM EFM32 Library CMU ClockDivGet CMU Clock TypeDef clock EQ ACMP Get clock divisor prescaler EQ ADC CMU ClockSelectGet CMU Clock TypeDef clock E Get currently selected reference clock used for a clock branch EQ AES CMU ClockDivSet CMU Clock TypeDef clock CMU_CIkDiv_TypeDef div amp BITBAND Set clock divisor prescaler t cup CMU ClockSelectSet CMU Clock TypeDef dock CMU Sele
6. m me AREGB7 AREGB6 AREGBO ALOGSEL Barrel shift right left The LCD controller contains an animation feature which can animate up to 8 segments 8 segment ring onthe LCD display autonomously The data displayed in the animated segments is a logic function AND or OR of two register bits for each segment The two register arrays LCD AREGA LCD AREGB can then be set up to be barrelshifted either left or right every time the Frame Counter overflows The Frame Counter can be set up to overflow after a configurable number of frames This is not covered by the LCD driver so here we have to manipulate the LCD registers by doing direct register writes The following registers must be set up LCD BACTRL Set Frame Counter Enable bit 2011 10 21 an0009 Revi 11 www energymicro com the world s most energy friendly microcontrollers Configure Frame Counter period by setting the FCTOP field Set Animation Enable bit Select either AND or OR as logic function lt Configure AREGA and AREGB shift direction LCD AREGA LCD AREGB Write data used for animation to these registers Play around a bit with the configuration of the animated segments and watch the results on the LCD display 2011 10 21 an0009 Rev1 11 www energymicro com the world s most energy friendly microcontrollers 7 Example 4 Energy Modes This example shows how to enter different Energy Modes EMx including Energy Mode 2 and w
7. of Contents Te INTRODUCTION P 2 1 1 How to use this application note eaaa eaaa eaaa I meme menm hem nennen aaa aana he rene rennes 2 1 2 Prerequisites cie ise tbe este eese uo e SAE A KAG snes beeen dean nonakane TE EET A Mane ER Seas SUME AA RUE nova ks ede 2 2 ReEGISiel eere nM EE ELS m TT 3 UND Cqe m 3 2 2 Register description iic iore titer de Ree Uni Oe aa PR a aaa La Ria XR n Denn UTR UDE e La iang ang RES Danan Ad 3 2 3 ACCESS AV DCS M Tm 4 2 4 CMSIS and EFMS2 LIB sci ecnciccs davai cov sa a con nasa ders NA cove Lest Da A Gene wa a derbies dene Lent Aa E aa na TEN E SAK aa dan 4 3 Example 1 Register Operation csse me me hene nennen he hene ti he hie he tieniti re rene rennen tree 8 3 1 Step 1 Enable timer Clock ioa e ren eaa e E aaa aga ni e simae E e tute cr eme sien te d 8 GD Slep 2 Start TIME s cocco erosion nee he v aged n e tnn ODER ana aal daa a A KE aa nah a at D aana Te DENN anaa 8 3 3 Step 3 Wait for threshold 5 iuter esee sanja adeng pede kent pan a ae niaga najana Rr DERE TE Ul NER UE Acuna sU RUE 8 3 4 Observation sas m 8 4 Example 2a Blinking LEDs with STK aana a eaaa eaaa aana aaa a aana aaa aaa nana nea een aana anana he he he ee he re nnne nennen 10 4 1 Step T Tumon GPIO clock eiit eere ete t GENE Ta aa aa Gaga eee ERE KANGEN a Ag aga aaa KE Ka KERENGAN EH 10 4 2 Step 2 Configure GPIO pins for LEDS s4 rangin a nanan
8. of the GPIO pins void GPIO PinModeSet GPIO Port TypeDef port unsigned int pin GPIO Mode TypeDef mode unsigned int out Use this function to configure the LED pin s as Push Pull outputs with the initial DOUT value set to 0 4 3 Step 3 Configure GPIO pin for button Looking into the User Manual for the STK we find that Push Button 0 PBO is connected to the following pin lt EFM32 Gxxx STK Port B pin 9 lt EFM32TG_STK3300 Port D pin 8 Configure this pin as an input to be able to detect the button state 4 4 Step 4 Change LED status when button is pressed Write a loop that toggles the LED s every time PBO is pressed Make sure that you do not only check that the button is pressed but also that it is released so that you only toggle the LED s once for each time you press the button 4 5 Extra Task LED animation Experiment with creating different blinking patterns on the LED s like fading and running LEDs if there are multiple LEDs Because the EFM32 runs at 14 MHz as default you need a delay function to be 2011 10 21 an0009 Revi 11 11 www energymicro com EFMS3Z the world s most energy friendly microcontrollers able to see the LEDs changing real time Using what you wrote for TIMERO in Example 1 you should be able to create the following function void Delay uintl16 t milliseconds Use the PRESC bitfield in TIMERO CTRL to reduce the clock frequency to a desired value 2011 10 21
9. the defines and library functions supplied in the CMSIS and efm32lib software libraries 2 1 Address The EFMS32 consists of several different types of peripherals CMU RTC ADCn Some peripherals in the EFM32 exist only as one instance like the Clock Management Unit CMU Other peripherals like Timers TIMERn exist as several instances and the name is postfixed by a number n denoting the instance number Usually two instances of a peripheral are identical but are placed in different regions of the memory map However some peripherals have a different feature set for each of the instances E g USARTO can have an IrDA interface while USART1 has not Such differences will be explained in the device datasheet and the reference manual The peripheral instances each have a dedicated address region which contains registers that can be accessed by read write operations The peripheral instances and memory regions are found in the device datasheets The starting address of a peripheral instance is called the base address The reference manual for the device series contains a complete description of the registers within each peripheral The address for each register is given as an offset from the base address for the peripheral instance Register address calculated from base and offset ADDRESSngaisrER BASEperiPHERAL_INSTANCE OFFSETperiIPHERAL 2 1 2 2 Register description The EFM32 devices use a 32 bit bus for write read access to the pe
10. 9 Revi 11 www energymicro com EFINIJ32 the world s most energy friendly microcontrollers 6 Example 3 LCD Controller This example requires either an STK or a DK with MCU board with LCD This example will show you how to use the LCD controller and display information on the LCD display The LCD controller also includes an autonomous animation feature which will also be demonstrated The efm32 workspace contains a project called kit name 3 Icd which will be used in this example 6 1 Step 1 Initialize the LCD controller The LCD controller driver is located in the development kit and starter kit library First you need to run the initialize function found in segmentlcd h to set up the LCD controller 6 2 Step 2 Write to LCD display By default all LCD segments are switched off after initialization The Icd controller driver includes several functions to control the different segment groups on the display A few examples are void SegmentLCD Number int value void SegmentLCD Write char string void SegmentLCD Symbol lcdSymbol s int on Experiment with putting your own text numbers symbols on the display and try to make things move about a bit You can use the Delay function from Example 2 If you did not complete this part of the example a Delay function can be found in the solution file 6 3 Step 2 Animate segments Figure 6 1 Animation Function Barrel shift right left m MD 44 FE Dym Dam DT cr
11. EFM 32 the world s most energy friendly microcontrollers EFM32 Getting Started ANO009 Application Note Introduction This application note is an introduction to development using the EFM32 devices from Energy Micro It is intended as a hands on tutorial and it is recommended to work through the tasks in the order they are presented Even though prior EFM32 knowledge is not required basic programming and electronics skills are needed to complete the tasks The examples can be run on both the following kits lt EFM32 Gecko Development Kit EFM32 Gxxx DK lt EFM32 Gecko Starter Kit EFM32_Gxxx_STK e EFM32 Tiny Gecko Starter Kit EFM32TG_STK3300 Things you will learn e Basic register operation Using EFM32Lib functions Blinking LEDs and reading buttons LCD controller e Energy Modes Real Time Counter operation This application note includes e This PDF document Source files zip e README file Example C code 4 ENER GY IDE workspaces with example projects PASE www energymicro com EFMS3Z the world s most energy friendly microcontrollers 1 Introduction 1 1 How to use this application note The source code for this application note is placed in individual folders named after the kit the different examples are intended for EFM32 Gxxx DK EFM32 Gxxx STK lt EFM32TG STK3300 Projects for each of the supported IDEs are found in separate folders iar arm etc The IAR pr
12. Figure 2 2 Grouped registers in GPIO 28 5 4 GPIO Px DOUT Port Data Out Register Bit Position Bit Name Reset Access Description 31 16 Reserved To ensure compatibility with future devices always write bits to 0 15 0 DOUT 0x0000 RW Data Out Data output on port In the CMSIS defines the port registers are grouped in an array P x When using this array we must index it using numbers instead of the port letters A 0 B 1 C 2 Accessing the DOUT register for port C can be done like this GPIO gt P 2 DOUT O0x000F 2 4 6 efm32_chip h In the source files included in this application note you will see the efm32_chip h included at the top and that CHIP Init is called at the beginning of the main functions Since early versions of the EFM32 devices were programmed differently in production the chip function is used to align the chip programming to the latest revision Do not run any code prior to running the CHIP Init function in your main function 2011 10 21 an0009 Revi 11 www energymicro com M32 the world s most energy friendly microcontrollers 3 Example 1 Register Operation This example will show how to write and read registers using the CMSIS defines You will also learn how to observe and manipulate register contents through the debugger in IAR Embedded Workbench While the examples are shown only for IAR the tasks can also be completed in other supported IDEs Open up efm32 workspace anxan0009 efm32 g
13. Msk WFI When in an active debug session the EFM32 will not be allowed to go below EM1 To measure the current consumption in EM2 you should therefore end the debugging session and reset the EFM32 with the reset button on the MCU board STK 7 5 Step 3 Enter EM2 To enter EM2 you must first enable a low frequency oscillator either LFRCO or LFXO before going to deep sleep same as for EM3 In this example we will enable the LFRCO and wait for it to stabilize by using the following efm32lib function void CMU_OscillatorEnable CMU_Osc_Typedef osc bool enable bool wait In addition the EMU efm32lib functions include functions for entering Energy Modes which you can use instead of setting the SLEEPDEEP bit and executing the WFl instruction manually void EMU EnterEM2 bool restore 2011 10 21 an0009 Revi 11 www energymicro com EF IMIS32 mm the world s most energy friendly microcontrollers 7 6 Step 4 Configure Real Time Counter To wake up from EM2 we will configure the Real Timer Counter RTC to give an interrupt after 5 seconds First we must enable the clock to the RTC by using the CMU efm3e2lib functions To communicate with Low Energy Frequency peripherals like the RTC you must also enable clock for the LE interface cmuClock CORE The efm32lib initialization function for the RTC requires a configuration struct as an input void RTC Init const RTC Init TypeDef init The struct is
14. ake up using RTC interrupt The efm32 workspace contains a project called kit name 4 energymodes which will be used in this example 7 1 Advanced Energy Monitor with DK The Development Kits includes current measurement of the VMCU power domain which is used to power the EFM32 and the LCD display on the MCU board The VMCU domain is also available on the prototyping board so other external components in your prototype can be added to the measurements The current measurement can be monitored real time on the TFT display on the main board and also on a PC using the energyAware Profiler available in Simplicity Studio 7 2 Advanced Energy Monitor with STK The EFM32 Gecko Starter Kit includes current measurement of the VMCU power domain which is used to power the EFM32 and the LCD display in addition to other components in the application part of the starter kit The real time current measurement can be monitored on a PC using the energyAware Profiler available in Simplicity Studio 7 3 Step 1 Enter EM1 To enter EM1 all you have to do is to execute a Wait For Interrupt instruction An intrinsic function for this is shown below WEI After executing this instruction you should see the current consumption drop 7 4 Step 2 Enter EM3 Entering EMS is also done by executing the WFl instruction only now with the SLEEPDEEP bit in the SCB SCR register Set this prior to the WFl instruction SCB gt SCR SCB SCR SLEEPDEEP
15. already declared in the code but you must set the 3 parameters in the struct before using it with the RTC Init function rtcInit compOTop true Next we must set compare value 0 COMPO in the RTC which will set interrupt flag COMPO when the compare value matches the counter value Chose a value that will equal 5 seconds given that the RTC runs at 32 768 kHz void RTC_CompareSet unsigned int comp uint32 t value Now the RTC COMPO flag will be set on a compare match but to generate an interrupt request from the RTC the corresponding interrupt enable bit must also be set void RTC IntEnable uint32 t flags Now the RTC interrupt request is enabled on a comparator match but to trigger an interrupt the RTC interrupt request line must be enabled in the Cortex M3 The IRQn Type to use is RTC IRQn NVIC EnableIRQ RTC IROn An interrupt handler for the RTC is already included in the code RTC_IRQHandler but it is empty In this function you should add a function call to clear the RTC COMPO interrupt flag If you do not do this the Cortex MG will be stuck in the interrupt handler since the interrupt is never deasserted Look for the RTC efm32lib function to clear the interrupt flag 7 7 Extra task LCD controller in EM2 As an extra task you can enable the LCD controller given that you have an LCD display on your kit and write something on the LCD display before going to EM2 You could also use the segment anima
16. are generally not intended for military applications Energy Micro products shall under no circumstances be used in weapons of mass destruction including but not limited to nuclear biological or chemical weapons or missiles capable of delivering such weapons A 2 Trademark Information Energy Micro EFM32 EFR logo and combinations thereof and others are the registered trademarks or trademarks of Energy Micro AS ARM CORTEX THUMB are the registered trademarks of ARM Limited Other terms and product names may be trademarks of others 2011 10 21 an0009 Revi 11 www energymicro com the world s most energy friendly microcontrollers B Contact Information B 1 Energy Micro Corporate Headquarters Postal Address Visitor Address Technical Support Energy Micro AS Energy Micro AS support energymicro com P O Box 4633 Nydalen Sandakerveien 118 Phone 47 40 10 03 01 N 0405 Oslo N 0484 Oslo NORWAY NORWAY www energymicro com Phone 47 23 00 98 00 Fax 47 23 00 98 01 B 2 Global Contacts Visit www energymicro com for information on global distributors and representatives or contact sales energymicro com for additional information Americas Europe Middle East and Africa Asia and Pacific www energymicro com americas www energymicro com emea www energymicro com asia 2011 10 21 an0009 Revi 11 www energymicro com I I INT EFNT32 the world s most energy friendly microcontrollers Table
17. ced Energy Monitor with STK sss eme ne ne hehe hehehe he he tiere tiere rennen 16 Tg SEP TEMS EMT aas 16 T4A Step 2 Enter EMI cereri niei onie Sa ea Sa a BAG e e E Na KE Aan SAE Bah NEG a REEE Aan eet ee 16 PO Olep 3 Enter EM2 c 16 7 6 Step 4 Configure Real Time Counter saanane eee eee he ne nene nenne 17 Tete Extra task ECD cotitroller in XEM rentrer cede ren eR ans eR Ka aa RA ne Ka ane A apa aa angan KA E Na bes ded aus 17 6 SUMMALY ESSI 18 9 Revision HIStory crenn e GA ENE a KN KA A EA AG ITA PA a a aaa AA NANANG alles KE AA jade BA AENG EA O AE BAE KE ENE este a 19 gil REVISION Vl dl aas aaa a ae KEN A A ANG BN a AE ENG NE EEE A ERA BAG Ta E KAG E KE a EE a E E 19 9 2 REVISION A ME 19 9 3 FREVISIOMN 1 03 oie aaa aia ag PG Na aia a aa Ng aha ade ba an E IES a an AA NA aja E An TAN A na a a an NA AG EE Na aaa BA 19 9 4 REVISION 1 02 aas maan wcities a eaaa aa ga anae al aben ia aa pagenan a a pa naa eaaa arana a a aaa anaa gagan a maar ara naa a anaa aaa gara a a janane paia ad 19 95 REVISION GM Onl ERE 19 9 6 Revision 1 00 sasana gag ag kakak aka EA NG Aa aa eb MeL EAE a Ega E EE LL e ULLUS 19 A Disclaimer and Trademarks ss sasae ma ren an ANGE ga a ga ed seca RN R RR DP aaa BANG KA BA Aa e BN GK aj KU ba Ka YR NG Ega REREN 20 Al DISCIAIMECR REEL LIII LM 20 A2 Trademark
18. ct 2011 10 21 an0009_Rev1 11 www energymicro com EFNT32 fhe world s most energy friendly microcontrollers To make programming of the EFM32 devices simpler Energy Micro also provides a complete C function library called efm32lib for all peripherals and core functions in the EFM32 These functions are found within the efm32 xxx c e g efm32 rtc c and efm32 xxx h files in the efm32lib folder 2 4 1 CMSIS Documentation Complete Doxygen documentation for the EFM32 CMSIS library and efm32lib is available in CMSIS Documentation in Simplicity Studio and in the software section of the web page 2 4 2 Peripheral structs In the EFM32 header files the register defines for each peripheral type are grouped in structs as defined in the example below Example 2 1 Peripheral struct typedef struct IO uint32 t CTRL I uint32 t STATUS IO uint32 t CHOCTRL C I IO uint32 t CHICTRL IO uint32 t IEN I uint32 t IF O uint32 t IFS O uint32 t IFC IO uint32 t CHODATA IO uint32 t CH1DATA O uint32 t COMBDATA IO uint32 t CAL IO uint32 t BIASPROG DAC TypeDef Together with the base address defines for the peripheral instance writing to a register CHODATA in the DACO peripheral instance can then be done like this DACO gt CHODATA 100 Reading a register can be done like this myVariable DACO gt STATUS 2 4 3 Bit field defines In the EFM32 header fil
19. ct TypeDef rel a CMU Select reference clock oscillator used for a clock branch EQ COMMON CMU HFRCOBandGet void DAC Get HFRCO band in use E 3 DBG CMU HFRCOBandSet CMU HFRCOBand TypeDef band Set HFRCO band and the tuning value based on the value in the calibration table made during production m DMA CMU_HFRCOStartupDelaySet uint32_t dela EQ EBI Set the HFRCO startup delay EQ EMU CMU HFRCOStartupDelayGet void 9 GPIO Get the HFRCO startup delay mg rc CMU OscillatorEnable CMU Osc TypeDef osc bool enable bool wait Enable disable oscillator 4 1 Step 1 Turn on GPIO clock In the list of CMU functions we find the following function to turn on the clock to the GPIO void CMU_ClockEnable CMU Clock TypeDef clock bool enable If we click on the function we are shown a description Figure 4 2 p 11 of how to use the function If we also click on the CMU Clock TypeDef link we are also taken to a list of the allowed enumerators for the clock argument To turn on the GPIO we then write the following CMU ClockEnable cmuClock GPIO true 2011 10 21 an0009 Revi 11 www energymicro com EF INv132 the world s most energy friendly microcontrollers Figure 4 2 CMU_ClockEnable function description a void CMU_ClockEnable CMU_Clock_TypeDef clock EFN 32 bool enable Energy_Micro_EFM32LIB D Mo
20. dules Enable disable a clock cM EFM32 Lib a T In general module clocking is disabled after a reset If a module clock is disabled the registers of that ACMP disabled modules have no effect One should normally avoid accessing module registers of a module w 3 ADC 9 AES Note If enabling disabling a LF clock synchronization into the low frequency domain is required If the amp amp BITBAND has completed Please refer to CMU FreezeEnable for a suggestion on how to reduce stalling 2 CHIP 54 cmu Parameters H tin clock The clock to enable disable Notice that not all defined clock points have separate enable COMMON tin enable r 9349 DAC e true enable specified clock d false disable specified clock H DBG TO om finiti li f file ef 5 EBI Definition at line 644 of file efm32_cmu c H EMU References BITBAND_Peripheral T9 cas Referenced by DMA_Init am r2c 9 INT Here is the call graph for this function 92 LCD gt Here is the caller graph for this function 93 LETIMER 4 2 Step 2 Configure GPIO pins for LEDs In Simplicity Studio under Kit Documentation we find the User Manual for the STK that we are using which tells us that the the user LED s are connected to the following pin s lt EFM32 Gxxx STK 4 LEDs on port C pins 0 3 lt EFM32TG_STK3300 1 LED on port D pin 7 Looking into the available functions for the GPIO we find the following function to configure the mode
21. es the registers for each peripheral type are grouped in structs as defined below for the DAC Example 2 2 Defines for REFRSEL bit field in DACn_CTRL define _DAC_CTRL_REFRSEL_SHIF 20 define _DAC_CTRL_REFRSEL_MASK 0x300000UL define DAC CTRL REFRSEL DEFAULT 0x00000000UL 20 define DAC CTRL REFRSEL 8CYCLES 0x00000000UL 20 define DAC CTRL REFRSEL 16CYCLES 0x00000001UL 20 define DAC CTRL REFRSEL 32CYCLES 0x000000020UL lt lt 20 define DAC CTRL REFRSEL 64CYCLES 0x00000003UL 20 define DAC CTRL REFRSEL DEFAULT 0x00000000UL define DAC CTRL REFRSEL 8CYCLES 0x00000000UL define DAC CTRL REFRSEL 16CYCLES 0x00000001UL define DAC CTRL REFRSEL 32CYCLES 0x00000002UL define DAC CTRL REFRSEL 64CYCLES 0x00000003UL 2011 10 21 an0009 Rev 11 www energymicro com E gw JB EIE Ws EF IM32 Example 2 3 Defines for LPFEN bit field in DACn_CTRL the world s most energy friendly microcontrollers define DAC_CTRL_LPFEN Ox1UL lt lt 12 define _DAC_CTRL_LPFEN_SHIF 12 define DAC CTRL LPFEN MASK 0x1000UL define DAC CTRL LPFEN DEFAULT 0x00000000UL 12 define DAC CTRL LPFEN DEFAULT 0x00000000UL 2 4 4 Register access examples When setting a bit in a control register it i
22. etting startediarvefm32 eww and select the kit name 1 register project in IAR EW In the main function in the 1 registers c inside Source Files there is a marker space where you can fill in your code 3 1 Step 1 Enable timer clock In this example we are going to use TIMERO By default the 14 MHz RC oscillator is running but all peripheral clocks are disabled hence we must turn on the clock for TIMERO before we use it If we look in the CMU chapter of the reference manual we see that the clock to TIMERO can be switched on by setting the TIMERO bit in the HEPERCLKENO register in the CMU peripheral 3 2 Step 2 Start timer Starting the Timer is done by writing a 1 to the START bit in the CMD register in TIMERO 3 3 Step 3 Wait for threshold Create a while loop that waits until counter is 1000 before proceeding 3 4 Observation Make sure the kit name 1 register project is active by pressing the corresponding tab at the bottom of the Workspace window Then press the Download amp Debug button Figure 3 1 p 9 Then go to View gt Register and find the STATUS register in TIMERO When you expand this you should see the RUNNING bit set to 0 Place your cursor in front of the line where you start the timer and press Run to Cursor Then watch the RUNNING bit get set to 1 in the Register View when you Single Step over the expression As you continue to Single Step you will see the content of the CNT registers increasing Try writi
23. g ahan Tara ne eem pega kag Aa naa aa ag a inaa na ii bai 11 4 3 Step 3 Configure GPIO pin for button sakke k akena rene m mmm me aaa anan nana aee 11 4 4 Step 4 Change LED status when button is pressed kaka a eaaa eaaa eaaa eaaa meer 11 4 5 Extra Task LED animation cccceeeeee cece eee cee e eee eee eee ne me heme hem nennen tenentem ren ren rennen ren ten ree rene 11 5 Example 2b Blinking LEDS With DK ierit dn errem ene RE RE Ya IRA EN ds ie REPLIES Ia eR TR EE ER DE UE Po ARR Re 13 5 1 Board Support LIDPANY asasaran Kaanane Kae ab ka adeng AGE ga Bg rne rau BA DANA At P RUM ADU RIP MU Ing de a ndan IR URDU Ne tees 13 5 2 Step 1 Change LED status when joystick is moved sssssssss eene 13 5 3 Extra Task LED aMiMatOM se sasa L 13 6 Example lt 3 LCD Controler x t icc seta nc aiei te retina iet SINGA ade aren Gia EEA acess E E EEA ETE a aaa ere 14 6 1 Step 1 Initialize the LCD controller 20 2 0 HH Hehe en ee he hene nennen 14 6 2 Step 2 Write to LCD display 5 ssasa sia aaa wai Da a ba api imanna Badan m meme meme mem mem nennen mente ente ren rennen BAGE KAG 14 6 3 Step 2 Animate Segments saanak riiin eres tenter eod ndn Poder e EE Ric ar REA E ag ada ete A ERA NG EE A E RE teas 14 Ac Example 4 Energy Mode Sassa 16 7 1 Advanced Energy Monitor with DK 0 0 nee ne ne ee ne nennen 16 7 2 Advan
24. ision 2011 10 21 an0009 Revi 11 www energymicro com M32 the world s most energy friendly microcontrollers A Disclaimer and Trademarks A 1 Disclaimer Energy Micro AS intends to provide customers with the latest accurate and in depth documentation of all peripherals and modules available for system and software implementers using or intending to use the Energy Micro products Characterization data available modules and peripherals memory sizes and memory addresses refer to each specific device and Typical parameters provided can and do vary in different applications Application examples described herein are for illustrative purposes only Energy Micro reserves the right to make changes without further notice and limitation to product information specifications and descriptions herein and does not give warranties as to the accuracy or completeness of the included information Energy Micro shall have no liability for the consequences of use of the information supplied herein This document does not imply or express copyright licenses granted hereunder to design or fabricate any integrated circuits The products must not be used within any Life Support System without the specific written consent of Energy Micro A Life Support System is any product or system intended to support or sustain life and or health which if it fails can be reasonably expected to result in significant personal injury or death Energy Micro products
25. ng a different value to the CNT register by entering it directly in the Register View 2011 10 21 an0009 Rev 11 www energymicro com Er Nv1T32 the world s most energy friendly microcontrollers Figure 3 1 Debug View in IAR Reset E Embedded Workbench IDE T ties p int main void rii nc Initialize chip CHIP init Source Files C3 Output Write a program that waits for 1000 cycles usii continues to the while 1 1oop at the end of the i Enable clock for TIMERO CMU gt HFPERCLKENO CMU HFPERCLKENO TIMERO Start TIMERO TIMERO CMD TIMER CMD START cooococoocoooooowmrx e 0x00000000 0x00000000 0x00000000 0x00000000 0x0000FFFF 0x00000000 0x00000078 0x00000000 Wait until counter value is over 1000 FITIMERO_IEN while TIMERO gt CNT lt 1000 F TIMERO_IF Do nothing just wait TIMERO IFS H ITIMERO IFC H ITIMERO TOP Stay in this loop forever at end of program BJTIMERO TOPB while 1 TIMERO CNT H ITIMERO ROUTE an0009 Rev1 11 www energymicro com the world s most energy friendly microcontrollers 4 Example 2a Blinking LEDs with STK Since accessing the LEDs is done differently for the Development Kits and the Starter Kits this example is split into two parts 2a for STK and 2b for DK In this example for the STKs the aim is to use the GPIO pins to light up the LEDs on the STK and change the LED configuration every time a button
26. ojects are also collected in one common workspace called efm32 eww whereas the ARM Keil projects must be handled separately Since the projects are slightly different for the various kits make sure that you open the project that is prefixed with the name of the kit you are using The code examples in this application note are not complete and the reader is required to fill in small pieces of code through out the exercises If you get stuck a completed code file postfixed with solution c exists for each examples 1 2 Prerequisites The examples in this application note require that you have one of the supported EFM32 kits at hand Before you start working on this tutorial you should make sure you have done the following steps Installed the latest Segger J Link drivers www segger com cms jlink software html Installed Simplicity Studio www energymicro com software simplicity studio Installed an IDE that supports the EFM32 device you have on your kit In Simplicity Studio you should also make sure that you have all the available packages installed and up to date You can ensure this by clicking on Add Remove and pressing the Install All button You will also need to click on Updates and press the Update All button 2011 10 21 an0009 Rev 11 www energymicro com EF Nv132 the world s most energy friendly microcontrollers 2 Register Operation This chapter explains the basics of how to write C code for the EFM32 devices using
27. ripherals and each register in a peripheral contains 32 bits numbered 0 31 Unused bits are marked as reserved and should not be modified The bits used by the peripheral can either be single bits e g DIFF bit in Figure 2 1 p 4 or grouped together in bitfields e g REFRSEL bitfield in Figure 2 1 p 4 Each bitfield is described with the following attributes Bit position Name Reset value Access type Description 2011 10 21 an0009 Rev 11 www energymicro com EFIM3Ss2 the world s most energy friendly microcontrollers Figure 2 1 Example register description 26 5 1 DACn_CTRL Control Register Bit Position 8E E amp amp ele REFRSEL PRESC LPFFREQ OUTMODE CONVMODE OUTENPRS SINEMODE DIFF Bit Name Reset Access Description 31 22 Reserved To ensure compatibility with future devices always write bits to 0 21 20 REFRSEL 0x0 RW Refresh Interval Select Select refresh counter timeout value A channel x will be refreshed with the interval set in this register if the REFREN bit in DACn_CHxCTRL is set 8CYCLES Al channels with enabled refresh are refreshed every 8 prescaled cycles 16CYCLES AI channels with enabled refresh are refreshed every 16 prescaled cycles 32CYCLES AI channels with enabled refresh are refreshed every 32 prescaled cycles 64CYCLES All channels with enabled refresh are refreshed every 64 prescaled cycles
28. s important to make sure you do not unintentionally clear other bits in the register To ensure this the mask with the bit you want to set can be OR ed with the original contents as shown in the example below DACO gt CTRL DACO CTRL DAC CTRL LPFEN or more compactly DACO gt CTRL DAC CTRL LPFEN Clearing a bit is done by ANDing the register with a value with all bits set except for the bit to be cleared DACO gt CTRL DACO gt CTRL amp DAC CTRL LPFEN or DACO gt CTRL amp 2 DAC_CTRL_LPFEN When setting a new value to a bit field containing multiple bits a simple OR function will not do since you will risk that the original bit field contents OR ed with the mask will give a wrong result Instead you should make sure to clear the entire bit field and only the bit field before you OR in the new value like shown below DACO gt CTRL DACO gt CTRL amp DAC CTRL REFRSEL MASK DAC CTRL REFRSEL 16CYCLES 2 4 5 Grouped registers Some registers are grouped together within each peripheral An example of such a group is the registers associated with each GPIO port like the Data Out Register DOUT in Figure 2 1 p 4 Each GPIO port A B C contains a DOUT register and the description below is common for all of these The xin GPIO Px DOUT indicates the port wild card 2011 10 21 an0009 Revi 11 www energymicro com E rNvT32 the world s most energy friendly microcontrollers
29. simultaneously As the DVK functions also take care of all the settings needed for the DK connection like GPIO settings etc you do not need to run any other efm32lib functions 5 2 Step 1 Change LED status when joystick is moved Write a while loop that increases a value every time the joystick is moved and display this value on the LEDs Make sure that you do not only check that the button is pressed but also that it is released so that you only toggle the LED s once for each time you press the button The 16 user LEDs on the DK are configured by the following function void DVK setLEDs uint16_t leds Look inside dvk h for a function to read the joystick status as well Please note that by default the buttons and joystick on the DK are used to control the menu on the TFT display To use the buttons and joystick with the EFM32 you need to press the AEM button The button joystick status is shown in the upper right hand corner of the TFT display 5 3 Extra Task LED animation Experiment with creating different moving patterns on the LEDs like fading and running LEDs Because the EFM32 runs at 14 MHz as default you need a delay function to be able to see the LEDs changing real time Using what you wrote for TIMERO in Example 1 you should be able to create the following function void Delay uintl16 t milliseconds Use the PRESC bitfield in TIMERO CTRL to reduce the timer clock frequency to a desired value 2011 10 21 an000
30. tion you made in the previous example in EM2 2011 10 21 an0009 Revi 11 www energymicro com EFIM3Ss2 the world s most energy friendly microcontrollers 8 Summary Congratulations You now know the basics of Energy Friendly Programming including register and GPIO operation use of basic functions on the DK STK and LCD in addition to handling different Energy Modes in the EFM32 and the efm32lib CMSIS functions The Examples section in Simplicity Studio contains several more examples for you to explore and more Application Notes are found in the App Notes section 2011 10 21 an0009 Rev1 11 www energymicro com EFMS3Z the world s most energy friendly microcontrollers 9 Revision History 9 1 Revision 1 11 2011 10 21 2011 09 08 Updated IDE project paths with new kits directory 9 2 Revision 1 10 2011 09 08 Added support for Tiny Gecko Starter Kit EFM32TG STK3300 9 3 Revision 1 03 2011 05 18 Updated projects to align with new bsp version 9 4 Revision 1 02 2010 11 19 Corrected solution c files for new EFM32LIB functions Corrected pdf document for new EFM32LIB functions 9 5 Revision 1 01 2010 11 16 Changed software documentation to use the segmentlcd c functions Icdcontroller c is deprecated Added section about CMSIS Doxygen documentation Changed example folder structure removed build and src folders Updated chip init function to newest efm32lib version 9 6 Revision 1 00 2010 09 20 Initial rev
Download Pdf Manuals
Related Search
Related Contents
Direttiva 2009/104/CE del Parlamento europeo e del Consiglio, del Samsung HL-R6168W Manuel de l'utilisateur RSTC1000 HMI/PLC Design Guide WEB CONTROL カタログ - 特殊工機 Pentax K-7 Digital Camera User Manual Samsung 19-inčni LED monitor napredne ergonomije za poslovne primjene Priručnik za korisnike Solar Scintillation Monitor User manual Régulateur Rutland HRDi Copyright © All rights reserved.
Failed to retrieve file