ADC¶
Overview¶
This sample demonstrates how to use the ADC driver API. It reads ADC samples from two channels specified in the devicetree and prints the readings on the console. If voltage of the used reference can be obtained, the raw readings are converted to millivolts.
Here is a minimal devicetree fragment which supports this sample.
As shown, AIN0 is assigned to Channel 0, and VDD_GPIO to Channel 1.
Requirements¶
Before you start, check that you have the required hardware and software:
- 1x nRF9151 Connect Kit
- 1x USB-C Cable
- A computer running macOS, Ubuntu, or Windows 10 or newer
Building the sample¶
To build the sample, follow the instructions in Getting Started Guide to set up your preferred building environment.
Use the following steps to build the ADC sample on the command line.
-
Open a terminal window.
-
Go to
NCS-Project/nrf9151-connectkit
repository cloned in the Getting Started Guide. -
Build the sample using the
west build
command, specifying the board (following the-b
option) asnrf9151_connectkit/nrf9151
.The
-p
always option forces a pristine build, and is recommended for new users. Users may also use the-p auto
option, which will use heuristics to determine if a pristine build is required, such as when building another sample.Tip
You can also build this sample for the
nrf9151_connectkit/nrf9151/ns
target. In such a case, the sample has Cortex-M Security Extensions (CMSE) enabled and separates the firmware between Non-Secure Processing Environment (NSPE) and Secure Processing Environment (SPE). Because of this, it automatically includes the Trusted Firmware-M (TF-M). -
After building the sample successfully, the firmware with the name
merged.hex
can be found in thebuild
directory.
Flashing the firmware¶
Connect the nRF9151 Connect Kit to the computer with a USB-C cable:
Then flash the sample using west flash
:
Tip
In case you wonder, the west flash
will execute the following command:
Testing¶
After programming the sample, test it by performing the following steps:
-
Open up a serial terminal, specifying the correct serial port that your computer uses to communicate with the nRF9151 SiP:
- Start PuTTY.
-
Configure the correct serial port and click Open:
-
Press the DFU/RST button to reset the nRF9151 SiP.
-
Observe the output of the terminal. You should see the output, similar to what is shown in the following: