Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

ADC with NRF24LE1 (Part 2/14)

By Amanpreet Singh May 7, 2023

ADC with NRF24LE1

We have studied about the first program on the NRF module which was very simple and we have been successful in blinking the LED.

Now, if we wish to make anything with NRF, we must know how to take analog inputs as most of the sensor is analog. In this article, we will see how to use the inbuilt ADC of NRF and how we can use any analog sensor and convert its value into digital

Prototype of NRF24LE1 Interfacing with ADC

Fig. 1: Prototype of NRF24LE1 Interfacing with ADC

Some important specs about inbuilt ADC of NRF24LE1 are :

• 6, 8, 10 or 12 bit resolution – It means we have option to choose 6-bit, 8-bit, 10-bit or 12-bit ADC.

• 14 input channels – 14 input pins for input analog signal

• Single ended or differential input- Single line input or Two line input

• Full-scale range set by internal reference, external reference or VDD – To set the maximum analog voltage to be sensed.

• Single step mode – Convert the signal and then stop 

• Continuous mode with 2, 4, 8 or 16 kbps sampling rate – Continuously converts the signal unless interrupted.

• Low current consumption; only 0.1mA at 2 kbps

Image showing interfacing of NRF24LE1 with ADC

Fig. 2: Image showing interfacing of NRF24LE1 with ADC

These are the specifications we have extracted from the datasheet. Now to understand the code, we have taken an excerpt from the example codes provided by Nordic. Let’s understand the main part of code line by line.

Functions provided by Nordic library

FUNCTION NAME INPUT PARAMETER OUTPUT DESCRIPTION
hal_adc_set_input_channel() AIN0 – AIN13 – Set the input channel
hal_adc_set_reference() INT/VDD/AIN3/AIN9 –

Set the reference voltage

INT – Internal 1.22V reference

VDD – 3.3V reference

AIN3/AIN9 – external reference

hal_adc_set_input_mode()

SINGLE/DIFF_AIN2/

DIFF_AIN6

–

Set the type of input

SINGLE – Single ended input

DIFF_AIN2 – Differential input with AIN2 as inverting input

DIFF_AIN6 – Differential input with AIN6 as inverting input

hal_adc_set_conversion_mode() SINGLE_STEP/CONTINOUS –

Set the conversion mode

SINGLE_STEP – Single step

CONTINOUS – Continuous

hal_adc_set_resolution()

RES_6BIT/ RES_8BIT/

RES_10BIT/ RES_12BIT

–

Set ADC resolution

RES_6BIT – 6 bit resolution

RES_8BIT – 8 bit resolution

RES_10BIT – 10 bit resolution

RES_12BIT – 12 bit resolution

hal_adc_set_data_just() JUST_LEFT/JUST_RIGHT –

Justify the position of output data

JUST_LEFT – Left position

JUST_Right – Right position

hal_adc_start() – – Start ADC conversion
hal_adc_busy() – 0/1

Check status of conversion

0 – Not busy

1 – Busy

hal_adc_read_LSB() – Byte Read the LSB of the converted data
hal_adc_read_MSB() – Byte Read the MSB of the converted data

 

// Configure ADC

hal_adc_set_input_channel (HAL_ADC_INP_AIN0) ;

Here we need to assign which input pin we are setting for the analog input. As we are using P0.0 so we have set that by HAL_ADC_INP_AIN0

hal_adc_set_reference (HAL_ADC_REF_VDD) ;

The ADC reference voltage is kept same as the VDD (Supply Voltage), which is 3.3V

hal_adc_set_input_mode (HAL_ADC_SINGLE) ;

As we are using single input, so it is set at HAL_ADC_SINGLE.

hal_adc_set_conversion_mode (HAL_ADC_SINGLE_STEP) ;

While in ADC conversion, we can set the conversion mode. Here we have set it as single step

hal_adc_set_resolution (HAL_ADC_RES_8BIT) ;

We can also set the resolution before the controller starts the ADC operations. We are setting it to 8 bit

hal_adc_set_data_just (HAL_ADC_JUST_RIGHT) ;

We can adjust the data right or left in ADC operation. We are adjusting it to the right

Please find below the main loop where ADC operation is taking place

While (true)
  {
    hal_adc_start ();                                 // Start the ADC conversion
    while( hal_adc_busy() )                         // Wait for the ADC to finish a conversion
    {
}
 P1 = hal_adc_read_LSB();                        // Write the ADC result to P1
  }
}
We have demonstrated the experiment using a video too. Here we have given the analog voltage between 0 and 3.3V using potentiometer.
We have attached Led’s at P1 port. The numbers of led’s that are ON will vary according to the input analog voltage given at the Analog pin
You can compile the code provided here using Keil software and burn the NRF using the burner to see the experiment by yourself.
Stay tuned with us while we are writing more for you.
Have a good day!!

 

Project Source Code

###

//Program to 

/* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.

 *
 * The information contained herein is confidential property of Nordic
 * Semiconductor ASA.Terms and conditions of usage are described in detail
 * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 *
 * Licensees are granted free, non-transferable use of the information. NO
 * WARRENTY of ANY KIND is provided. This heading must NOT be removed from
 * the file.
 *
 * $LastChangedRevision: 133 $
 */
 
/** @file
 * @brief ADC continuous mode example
 * @defgroup adc_cont_example ADC continuous mode example
 * @{
 * @ingroup nrf_examples
 *
 * @brief This example samples P00 using ADC continuous mode a rate of 2 Ksps
 * and outputs the 8 bit sample value on P1.
 *
*/
 
//lint -e716
//lint -e714
 
#include "nrf24le1.h"
#include "hal_adc.h"
#include
 
void delay(unsigned int us)
{
  while(us--)
  {
    _nop_();
  }
}
 
void main()
{
  // Set P1 as output
  P1DIR = 0;
P10 = 0;
 
  // Configure ADC
  hal_adc_set_input_channel(HAL_ADC_INP_AIN0);
  hal_adc_set_reference(HAL_ADC_REF_VDD);
  hal_adc_set_input_mode(HAL_ADC_SINGLE);
  hal_adc_set_conversion_mode(HAL_ADC_CONTINOUS);
  hal_adc_set_sampling_rate(HAL_ADC_2KSPS);
  hal_adc_set_resolution(HAL_ADC_RES_8BIT);
  hal_adc_set_data_just(HAL_ADC_JUST_RIGHT);
 
  // Enable MISC interrupts to enable ADC interrupt
  MISC = 1;
  // Enable global interrupts
  EA = 1;
  // Start ADC conversion
  hal_adc_start();
 
  for(;;){}
}
 
// ADC (MISC) interrupt
ADC_ISR()
{
  int val = 0;
val = hal_adc_read_LSB();
P10 = 1;
delay(1000);
delay(val * 4);
P10 = 0;
delay(19000 - val * 4);
 
}
/** @} */
 

###

 


Circuit Diagrams

Circuit-Diagram-NRF24LE1-Interfacing-ADC

Project Video


Filed Under: Tutorials

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • IGBTs without negative gate drive
  • High failure rate of LLC converter
  • Broad band impedance matching network for loop antenna using transformer for wireless power transfer
  • Earth leakage circuit with TL071
  • VHF radio

RSS Electro-Tech-Online.com Discussions

  • Pickit 5
  • turbo jet fan - feedback appreciated.
  • More fun with ws2812 this time XC8 and CLC
  • Pic18f25q10 osccon1 settings swordfish basic
  • I Wanna build a robot

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How IoT network topologies work
  • The top five AI startups to watch in 2025
  • STMicroelectronics unveils SoC based on secure MCU
  • Nexperia’s 48 V ESD diodes support higher data rates with ultra-low capacitance design
  • Taoglas releases Patriot antenna with 18 integrated elements covering 600 to 6000 MHz

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe