Setting Up a Sample ADC Capture App With Wireless Mesh Stacks on EFR32MG Parts Using Simplicity Studio
The EFR32 Mighty Gecko has a wide number of peripherals and significant flexibility in capabilities, power use and pinouts. These powerful options also increase the complexity of chip configuration as well as interaction with the EmberZNET Pro stack and Application Framework.
The following tutorial provides a very simplistic ADC sample app to show concepts such as the peripheral init structure, clocking, and using the cryotimer to send an approximately 1Hz ADC output to the Serial Terminal. The ADC pin is essentially hard-coded, but reference is made to the built-in em_adc.c file for further, more sophisticated ADC development.
In addition, the tutorial includes explanations for using Simplicity Studio's AppBuilder to develop this application, to accommodate users who have either not used Silicon Labs parts and software previously, or only have experience using Silicon Labs Ember Desktop and EM35x parts.
Simplicity Studio is our IDE of choice for EFR32 and any new EM35xx development. We recommend following the KBA below for installing and setting up Studio for best success with our wireless mesh stacks such as EmberZNet 5.7.x.
If you haven’t installed or used Simplicity Studio 4 with a WSTK, please see the linked KBA above, to walk through this process and make sure that all components are in place for this tutorial. Incomplete setup (specifically, not having a wireless module connected when installing) is the primary cause of difficulty beginning a wireless mesh project in Studio.
Create the Project:
Configure the Project:
Adding the ADC Peripheral and em_lib calls:
In the emberAfMainTickCallback, add the following:
emberAfAppPrint ("ADC: %4d\n\r",ADC_SampleVal);
Double-click on adc_sample_inits.c and review the file. You can see that there is an init structure where application-required settings are passed into the init functions.
adcSinglesetup() includes the clocking, voltage references, single/differential ADC settings, Peripheral Reflex System, port and IRQ settings.
cryotimerSetup() includes the use of a timer not used by the stack to trigger and print the ADC conversions.
In addition, you can see that there is a define for the ADC_INPUT_PORT adcPosSelAPORT1XCH22. APORTS are described in the EFR32xG1 Wireless Gecko Reference Manual. The EFR32MG1 Datasheet has tables to cross-reference the port designation with functions and pins. In this case, APORT1XCH22 refers to ADC0 on Pin #7 (PF6). On the WSTK, this pin is associated with Button PB0 so that we can sample at logic high and ground. You can later change the input pin to allow an outside voltage level to be measured.
This is just a simplified sample app, with a minimal configuration. However, if you look at the standard EFR32/adc.c, you can see a number of included pin definitions as well as clock setup, IRQ handling, resets, sleep handling, continuous vs single conversion, and ADC to voltage translation, all in a format more appropriate for full development.
Build, Upload and Run:
Congratulations, you’ve set up your ADC capture on the WSTK with EFR32 in the AppBuilder environment!
[Tip o' the hat to cgiga of the Silabs 32Bit MCU team for source code and help with this topic.]
Simplicity Studio 4 is a unified suite of development tools for Silicon Labs products. As the tool is very configurable, an installation flow is provided here to enable a user of the WSTK (SLSWSTK6000A: WSTK Mainboard PCB 4001 with Mighty Gecko EFR32MG wireless module 4153A (2.4GHz 13 dBm – EFR32MG1P132F256GM48) to get up and running quickly.
Note: You can also use the 4151A module (EFR32MG1P232F256GM48), but be sure to make the correct part selections when required. Each module has unique features and will not be properly recognized if not correctly specified.
Incomplete setup (specifically, not having a wireless module connected when installing) is the primary cause of difficulty beginning a wireless mesh project in Studio. This is a departure from Ember Desktop, and although it is very helpful to configure items that are connected, it isn’t something an ED or Studio user might normally be aware of.
Simplicity Studio V4 is now set up and ready for you to begin working on your Mighty Gecko projects.
Virtual UART is a feature that allows a serial UART interface to be emulated over the debug connector ordinarily used for programming and SerialWire debugging. On the EFR32MG, it makes use of SerialWire's SWO line for output and SerialWire's SWDIO (along with the ARM Cortex's ITM channel 8) for input. This feature is useful for devices that need to use a serial port for character printing or command line interfacing (CLI) during prototyping or debugging but which don't ordinarily provide UART access through standard USART pins. Virtual UART I/O is made available through a TCP socket on the debug adapter via TCP port 4900, also hosted as the "Serial 0" tab on the Simplicity Studio's "Console" view (accessed by Launch Console action in Devices window). Additionally, strings printed to Virtual UART output will appear as "UART" events in Simplicity Studio's Network Analyzer in the Events pane of the Capture view.
Software Requirements for EFR32MG:
As of this writing, the following caveats exist around use of this feature: