Is it possible to enter a low power mode, such as EM1, immediately after an interrupt completes? In my program, it is undesirable or unnecessary to wait until the program returns to main before going into a low energy mode.
Yes, but this requires setting the Sleep On Exit flag within the SCB module before executing __WFI() or __WFE(). The following code will implement this feature:
The EFM32 TIMER module has many different functions including up/down count, input capture, or output compare. It can be clocked from several sources, both internal and external. The module comes with a 16-bit counter with multiple modes, input capture, output compare, and PWM.
Fig: TIMER Overview
Three different sources can contribute to the clock input for the counter: peripheral high frequency clock (HFPERCLK), compare/capture channel 1 input (TIMn_CC1 pin or PRS channel), or underflow/overflow from the lower numbered neighbor timer. The timer has 5 output events that can trigger an interrupt. Barring the buffer overflow, all events also trigger a PRS Signal and a DMA request:
Compare match, input capture or buffer overflow (one per Compare/Capture channel)
If an interrupt is generated, the interrupt flag can be read from the TIMERn_IF register and cleared by writing TIMERn_IFC.
What are the correct components to be selected for oscillator circuits in EFM32 devices?
EFM32 microcontrollers contain two crystal oscillators: the Low Frequency Crystal Oscillator (LFXO) and the High Frequency Crystal Oscillator (HFXO). These oscillators need an external clock or crystal and load capacitors connected to the crystal oscillator pins of the EFM32. The LFXO supports crystals with a nominal frequency of 32.768 kHz, while the HFXO supports frequencies from 4 to 32 MHz. Both the high and low frequency clock sources can be used simultaneously.
Fig: The Pierce Oscillator in the EFM32
Crystal parameters include the quality factor Q (a measure of efficiency in the crystal), equivalent series resistance (resistance in the crystal during oscillation which varies with resonance frequency), and drive level (measure of the power dissipated in the crystal), among others.
In addition, there must be a Minimum Negative Resistance (negative resistance of the amplifier has to exceed supplied to exceed the energy dissipated in the circuit), frequency stability (the maximum frequency deviation from the specified oscillating frequency over the given operating temperature range), and frequency tolerance (the maximum frequency deviation from the specified oscillating frequency at 25°C).
How can I use the Watchdog module on the EFM32 microcontrollers?
The Watchdog module helps in generating a reset in case of a system failure (like an ESD pulse) to increase application reliability. It is essentially a timer which (when enabled) must be cleared by software regularly. If software does not clear it, a Watchdog reset is activated, thereby providing recovery from a software stalemate.
Fig: Watchdog Timer Operation
The Watchdog timer (WDOG) on the EFM32 devices is a Low Energy Peripheral module that can be configured to generate a system reset in case it is not cleared by software before the given deadline. Clearing the watchdog means that the value counted to by the timer is set to zero. This is the normal procedure carried out by software when the system is running correctly. But if the system is running incorrectly, the CPU fails to reset the Watchdog timely which results in the Watchdog generating a system reset on reaching a certain threshold value.
The Watchdog can be configured to use one of three different clock sources: LFRCO, LFXO or ULFRCO. ULFRCO (Ultra Low Frequency RC Oscillator) is a separate and dedicated Watchdog 1 kHz RC oscillator that also runs in EM3. This oscillator is always enabled and is included in all current consumption numbers. The other two clock sources available for the Watchdog timer have higher accuracy but in turn need more energy to operate.
Easy configuration and operation of this module is offered by the emlib functions provided by Silicon Laboratories.
How can I use the EFM32 I2C module to talk to an I2C temperature sensor?
The EFM32 I2C module allows simple, robust, and cost-effective communication between integrated circuits. It allows connection of up to 128 individually addressable devices using only two bi-directional lines: clock (SCL) and data (SDA). Each of these connected devices can be either a master device or a slave device, with only master devices able to drive the clock line.
The I2C protocol and the EFM32 I2C module feature several mechanisms for handling bus conflicts and contention.
Fig: I2C Bus
START and STOP conditions are used to initiate and stop transactions on the I2C bus. A START condition is generated by pulling the SDA line low while SCL is high, and a STOP condition is generated by pulling the SDA line high while SCL is high.
How can I use the EFM32 GPIO module to configure port pins?
The GPIO module allows for configuration of the I/O pins, which are used by the microcontroller to interact with any external system components.
Fig: Pin Connections Overview
While on the output side you can drive the pins by writing the corresponding bit in the DOUT register, in input mode, each pin has a selectable filter that can suppress glitches up to 50 ns. The pin value is read from the DIN register. The pin can also be used as an external interrupt source, analog input, or PRS producer, which connects it to one of the 8 PRS channels.
How can I use the Direct Memory Access (DMA) on EFM32 devices?
The DMA is used for data transfer between any readable source and writable destination address within the EFM32 address space without CPU intervention. This can be initiated either by a peripheral setting a DMA request signal or by the CPU directly.
Fig: The EFM32 Bus Matrix
The many channels of EFM32 DMA may be individually configured with a transfer mode and source and destination memory address. The configuration for the DMA transfers is split into 3 main areas: DMA descriptors, DMA registers, and registers in the trigger peripheral.
How do I program EFM32 devices through the UART without a debugger?
With the use of the EFM32 UART bootloader, users can program EFM32 devices through the UART without a debugger.
The UART bootloader has a destructive write mode so users can overwrite the bootloader and use the entire flash space for user applications. The contents of the flash can be verified through a CRC checksum, and debug lock can be enabled to protect IP. Since the bootloader uses the established XMODEM-CRC protocol for data upload, any serial terminal program can be used to communicate with the bootloader. This UART bootloader is preprogrammed in all EFM32 devices that don't support USB.
Fig: Transferring a file using XMODEM-CRC with Tera Term
The bootloader communicates using a UART interface, and it supports single-character commands to: program (upload/overwrite), verify (calculate checksums), secure (writeprotect, lock the debug port), etc. the EFM32 device. It is invoked after a reset while DBG_SWCLK is pulled high.
What kind of hardware design considerations should be kept in mind for EFM32 and EZR32 MCUs?
For system designers who require an overview of the hardware design considerations for EFM32 32-bit MCUs and the MCU portion of EZR32 Wireless MCU devices, there are some things to be kept in mind. This includes, for instance, how to provide a robust power supply to the chip, connection to the debug interface and external clock sources.
Power Supply: Even though the EFM32 or EZR32 supports a wide voltage range and has a very small average current consumption, proper decoupling is crucial. Decoupling capacitors make the current loop between supply, MCU and ground as short as possible for high frequency transients.
Fig: Power supply - standard decoupling
Debug Interface and External Reset Pin (RESETn): The debug interface consists of the SWCLK (clock input) and SWDIO (data in/out) lines, in addition to the optional SWO (serial wire output). The RESETn pin includes an internal pull-up resistor and can therefore be left unconnected if no external reset source is required. Forcing this RESETn pin low generates a reset of the EFM32 or EZR32.
Fig: . Connecting the EFM32 to an ARM 20 pin debug header
External clock sources: The EFM32 or EZR32 support different external clock sources to generate the low and high frequency clocks in addition to the internal LF and HF RC oscillators. The possible external clock sources for both the LF and HF domains are external oscillators (square or sine wave) or crystals/ceramic resonators. This section describes how the external clock sources should be connected.
How can a tickless calendar based on the Real Time Counter for the EFM32 be implemented in software?
Many microcontroller applications need to keep track of the time and date with minimum current consumption. To do this, you can use a software implementation of a low current tickless calendar on the EFM32. The calendar uses the standard C library time.h, where an implementation of the time() function calculates the calendar time based on the RTC counter value.
C Date and Time - These functions are based on Unix time, which is defined as a count of the number of seconds passed since the Unix epoch (midnight UTC on January 1, 1970)
Clock.c - Contains the functions that are needed for the tickless calendar. It also keeps track of how many times the RTC has overflowed since the start time. This is required for time keeping to be correct when the RTC overflows. Clock.c contains many functions and constants like clockInit(), clockSetStartCalendar() and clockOverflow().
Clock_tc.c - Clock_tc.c is a temperature compensated version of clock.c.
Calendar_ui.c - Calendar_ui.c contains the functions that handles the user interface.
How to choose clock sources, prescaling, and clock calibration in a CMU module?
EFM32 devices have several internal clock sources available, ranging from 32 kHz up to 28 MHz. Selecting the right clock source is key for creating low energy applications.
The Clock Management Unit (CMU) on the EFM32 or EZR32 controls the oscillators and clocks. It can enable or disable the clock to the different peripherals individually, as well as enable, disable, or configure the available oscillators. This allows for minimizing energy consumption by disabling the clock for unused peripherals or having them run at lower frequencies.
Overview: The EFM32 or EZR32 devices have 3 main clock branches (HFCLK, LFACLK, and LFBCLK), which are then routed to the different peripherals. Some peripherals, like the Low Energy peripherals, have dedicated prescalers. Other peripherals need to be prescaled by prescaling the clock source, which will affect all the peripherals driven by the same source.
Clock Sources: There are 5 selectable clock sources:
1-28 MHz High Frequency RC Oscillator (HFRCO)
4-32 MHz High Frequency Crystal Oscillator (HFXO)
32.768 kHz Low Frequency RC Oscillator (LFRCO)
32.768 kHz Low Frequency Crystal Oscillator (LFXO)
(Happy Gecko only) 48/24 MHz Universal Serial High Frequency RC Oscillator (USHFRCO)
Fig: Clocks and Oscillators overview
To select the clock source for a branch (HFCLK, LFA or LFB), the chosen oscillator must be enabled before the switch is done. If this is not done, the modules that are running from that clock branch will stop. In the case of selecting a disabled oscillator for the HFCLK branch, the CPU will stop and can only be recovered after a reset.
Energy Modes: The energy mode of the EFM32 or EZR32 determines which oscillators are active; for instance, in EM0 and EM1, all the oscillators can be enabled and used as clock sources. Wake up considerations include waking up from different energy modes, restoring the oscillator, start-up current and the glitch detector.
External clock sources: The EFM32 or EZR32 can be clocked by an external clock signal such as a square or a sine wave like a crystal or ceramic oscillator. This selection takes place using the HFXOMODE or LFXOMODE bitfields in the CMU_CTRL register.
RC Oscillator calibration: The CMU has built-in hardware support to efficiently calibrate the RC oscillators at run-time. It does this by comparing the HFCLK frequency with a selected reference clock (CALCLK).
Fig: Hardware support for calibration
Read the entire application note here which also contains software examples detailing how to enable and select clock sources, prescaling and changing HFRCO bands, and how to use the calibration routine.
How do I use Real Time Counters and Backup Real Time Counters?
Many microcontroller applications have long time intervals that require almost no activity. The EFM32 devices feature many modes in which these intervals are spent in an appropriate sleep mode to save energy. Among these is the EM2, where the core and high-speed peripherals are shut down, while low-energy peripherals such as LCD, LEUART, and RTC may be enabled. These peripherals run on a low-frequency oscillator, so their current consumption is very low. This is where the RTC helps by keeping track of time and waking up from sleep mode.
The EFM32 family has two different real time counters: the RTC and the Backup RTC (BURTC).
RTC: The RTC increments a counter on each positive edge of its clock. When the value of the counter is equal to either of its compare registers, an interrupt is triggered (if enabled). This interrupt can wake up the EFM32 from EM2, and code execution is resumed.
Backup RTC: The Backup Real Time Counter (BURTC) is available in some of the EFM32 families. It allows for timekeeping in all energy modes and can run in EM4 with a total current consumption of less than 0.5 µA.
How do I reduce current consumption and enter different energy modes?
Energy saving is essential in battery-powered microcontroller applications, and this can be done by reducing the current consumption. This increases the mean time between battery charging or replacement. The EFM32 family supports such principles that reduce current consumption like:
Using appropriate Energy Modes
Exploiting low energy peripherals
Turning off unused modules / peripherals
Disabling clocks to unused modules / peripherals
Reducing clock frequency
Lowering the operating voltage
EFM32 has different energy modes ranging from normal mode (the default mode), sleep mode, deep sleep mode, stop mode, to shut off mode. These modes differ in energy consumption, CPU activity, available peripherals and clocks. By using the emlib functions, it is extremely simple to switch between them.
Since current consumption is highly dependent on clock frequency, selecting the correct oscillator and frequency is also an important aspect in low energy applications. This includes HFRCO band setting, enabling or disabling a clock to a module/peripheral, and prescaling clocks, among other such measures.
Read the complete application note for more details on the above and for software examples of energy modes and EM4 Wakeup. The prime number calculation code used in current consumption benchmarking is also included in this.
How do I use the EFM32 USART in synchronous (SPI) mode?
The EFM32 Universal Synchronous Asynchronous serial Receiver and Transmitter (USART) is a flexible serial communication module that can operate in either synchronous or asynchronous mode. The synchronous communication mode entails a separate clock signal being transmitted with the data and is compatible with the Serial Peripheral Interface Bus (SPI) standard.
Fig: USART overview
Synchronous (SPI) mode is set up using 4 lines: clock (CLK), data in and out (MISO and MOSI), and chip select (CS, also known as slave select, SS). The data lines consist of MOSI (Master Out Slave In) and MISO (Master In Slave Out). These lines are driven by the master and the slave, respectively.
Installing an IDE that supports the EFM32 device on the kit (if an IDE other than the one included in Simplicity Studio is desired)
C-code for EFM32 devices can be written using the defines and library functions supplied in the CMSIS and emlib software libraries.
Address: EFM32 consists of several different kind of peripherals - some existing only as one instance (like CMUs), while others exist exist as several instances. Peripheral instances each have a dedicated address region which contains registers that can be accessed by read/write operations.
Register description: EFM32 devices use a 32-bit bus for write/read access to the peripherals, and each register in a peripheral contains 32 bits, numbered 0-31. Each bitfield is described with attributes of bit position, name, reset value, access type and description.
Access types: Each register has a set access type for all of the bit fields within that register.
CMSIS and emlib: The Cortex Microcontroller Software Interface Standard (CMSIS) is a common coding standard for all ARM Cortex devices. A complete C-function library named emlib caters to all peripherals and core functions in the EFM32.
Read the complete application note here for detailed step-by-step examples on register operation, blinking LEDs with an STK, blinking LEDs with a DK, and using the segment LCD controller, memory LCD, and energy modes.
On EFM32 devices, is it required to poll SYNCBUSY on low frequency (asynchronous) peripheral registers if those peripherals are being clocked by HFCORECLK?
No. Synchronization is only required between the core clock domain and the low-energy peripheral clock domain if these domains are different. In the case where a low energy clock domain is clocked by the core clock or a derivative, no synchronization is required.