In this exercise, we will explore the advanced mode of the SAADC driver to measure voltage source (E.g., a battery) at a high sample rate. We will use a hardware TIMER instance to trigger sampling through DPPI/PPI, without any CPU involvement.
Exercise steps
Open the code base of the exercise by navigating to Create a new application in the nRF Connect for VS Code extension, select Copy a sample, and search for Lesson 6 – Exercise 3.
Enable the driver by adding the following lines into the application configuration file prj.conf.
Copy
CONFIG_NRFX_SAADC=yCONFIG_NRFX_GPPI=y
Kconfig
We also need to enable the TIMER instance that will be used. Available TIMER instances differ between targets. For nRF52/nRF53/nRF91, we will use TIMER2, for nRF54L15, we will use TIMER22. This is done by enabling it in prj.conf:
2. Include the nrfx-related header files in the application.
We will use the nrfx SAADC, TIMER and (D)PPI drivers to configure the peripherals.
nRF52 Series chips have a PPI peripheral, while nRF54, nRF53 and nRF91 Series have a more flexible DPPI peripheral. nrfx provides a helper API (nrfx GPPI) that can be used to configure both peripheral variants through a common API. Add nrfx-related header files by including the following lines at the top (include section) of main.c:
3.3 In the function configure_timer(), declare the timer config struct. The parameter passed to NRFX_TIMER_DEFAULT_CONFIG will set the frequency of the timer. The timer config is used to initialize the instance of the timer driver. Since we will use (D)PPI to trigger sampling, no interrupts are needed, and we pass NULL to the event handler parameter:
3.4 We will use the COMPARE0 event from the TIMER to trigger sampling at the interval given by SAADC_SAMPLE_INTERVAL_US. The TIMER will be cleared every time the COMPARE0 event is hit, to create a recurring timer event. Add these lines to the end of the function configure_timer():
4.1 In this example, we will use double buffering, which requires two separate buffers that will be filled with samples sequentially. One buffer will be filled while the other buffer can be processed. Since we have a short sample interval, the buffer needs to be large enough for the CPU to start up and process the previous buffer before the new buffer is filled. Start by defining the buffer size for each of the buffers by adding this line close to the top of main.c:
Copy
#define SAADC_BUFFER_SIZE 8000
C
4.2 Next, let’s declare the two buffers by adding this line below the define section in main.c
4.3 To keep track of which of the two buffers should be assigned to the SAADC driver, we declare a variable corresponding to the current buffer index:
Copy
staticuint32_t saadc_current_buffer = 0;
C
4.4 We will reference the ADC defined in the Zephyr devicetree, to make the code more portable. To connect the SAADC interrupt to SAADC interrupt handler, add these lines in configure_saadc():
By default, the ADC is enabled in the board DTS file for all DKs supported by this course, but for custom boards you may have to enable it in your DTS or overlay file using the following code snippet:
Copy
&adc { status = "okay";};
Devicetree
4.5 Before using the SAADC driver, the driver instance must be initialized. We will again refer to the devicetree to get the configured priority of the ADC node and use this for the driver:
4.6 Declare the struct to hold the configuration for the SAADC channel used to sample the battery voltage. The macro NRFX_SAADC_DEFAULT_CHANNEL_SE() will create the default configuration struct for a single ended input for the provided analog input on channel 0.
The way of configuring pins for SAADC channels have changed for nRF54L15. Chose the tab below that matches your DK.
Connect a battery between GND and analog input (AIN0 or AIN4, depending on your target). Check the Hardware and Layout ->Pin assignment chapter in the Product specification to know which Pin is connected to the analog inputs on your choice of SoC/SiP. You can also connect a jumper wire between analog input 0 and VDD if you do not have a battery available.
4.7 Configure the SAADC channel using the previously defined channel configuration structure. The default configuration uses GAIN=1, which is too high to support supply voltage measurements. We need to change the gain config before configuring the channel:
The GAIN steps are different for nRF54L15 compared to previous SoCs. Chose the tab below that matches with your DK.
4.8 We will use the nrfx SAADC driver in advanced mode on channel 0 for this exercise. It is required to pass a configuration struct to the function, we will use the default defined configuration:
The default configuration disables OVERSAMPLING, BURST, and the internal timer, and it prevents the driver from triggering the START task when END event is generated (when a buffer have been filled). We will later configure triggering of the START task in HW through a (D)PPI channel to make sure there is no delay in buffer switching caused by other SW interrupts preempting the SAADC interrupt handler that would normally handle the buffer swapping. Passing an event handler to the last argument of the function will make the driver operate in non-blocking mode, we will implement the event handler in the next step. Add these lines to configure_saadc():
4.9 The SAADC peripheral can support double buffering by providing a new buffer pointer as soon as the previous buffer has been acquired by the peripheral (STARTED event generated). The SAADC driver can support this feature by calling the buffer set function twice. Call the function once for each of the two previously declared buffers:
5. Implement the event handler for the SAADC driver.
We will now implement the event handler for the SAADC driver, where events passed from the driver will be processed by the application. The available event types are as follows:
In this application, we will not use the limit or calibration features, and since we will use double-buffering, the NRFX_SAADC_EVT_FINISHED event should not happen. The event handler function is declared as saadc_event_handler() in the firmware.
5.1 The NRFX_SAADC_EVT_READY event will trigger when the first buffer has been initialized in the driver and the SAADC is ready for sampling. We will start the timer in this event.
Add this line under the case before the break:
Copy
nrfx_timer_enable(&timer_instance);
C
5.2 The NRFX_SAADC_EVT_BUF_REQ event will be generated whenever a buffer is acquired by the driver, and it can accept a new buffer. We will alternate between the two previously defined buffers and provide the correct one by incrementing a variable (saadc_current_buffer). Add these lines under the case before the break:
5.3 The final event we will handle is the NRFX_SAADC_EVT_DONE event, which is generated when a buffer has been filled with the requested number of samples. Since we are only measuring battery voltage in this example, we will calculate the average, minimum and maximum sample value of all samples in the buffer and output this on the log:
Copy
int64_t average = 0;int16_t max = INT16_MIN;int16_t min = INT16_MAX;int16_t current_value;for (int i = 0; i < p_event->data.done.size; i++) { current_value = ((int16_t *)(p_event->data.done.p_buffer))[i]; average += current_value;if (current_value > max) { max = current_value; }if (current_value < min) { min = current_value; }}average = average / p_event->data.done.size;LOG_INF("SAADC buffer at 0x%x filled with %d samples", (uint32_t)p_event->data.done.p_buffer, p_event->data.done.size);LOG_INF("AVG=%d, MIN=%d, MAX=%d", (int16_t)average, min, max);
C
6. Setup the (D)PPI channels.
Finally, we will setup the (D)PPI channels that will be used to trigger actions automatically in HW, without any CPU interaction.
Trigger SAADC->SAMPLE task based on COMPARE event from timer
Trigger SAADC->START task when SAADC->END event indicates that the buffer is full.
6.1 Declare variables used to hold the (D)PPI channel number. Add these lines to configure_ppi()
6.3 Each (D)PPI channel is assigned to one task and one event endpoint. The endpoints are the register address of the task or event as documented in the Product Specifications of the chip. Most drivers or HAL (Hardware Abstraction Layer) implementation where (D)PPI are relevant have APIs to get the addresses. Setup the first (D)PPI channel from TIMER->COMPARE0 event to trigger SAADC->SAMPLE task:
7. Build the application and flash it to your board.
8. Connect your analog input to a voltage source, just as you did in exercise 1.
This could be a dedicated power supply, a PPK2, a battery, or you can simply connect a wire between the analog input (AIN0) and VDD as shown below.
Note
ake sure that the voltage applied to the analog input does not exceed VDD. If you have a battery with a higher voltage level than VDD, you need to use a voltage divider between the battery and the input.
If you want to measure battery voltage directly from VDD, you can replace NRF_SAADC_INPUT_AIN0 or NRF_SAADC_INPUT_AIN4 (nRF54) with NRF_SAADC_INPUT_VDD.
9. Using a serial terminal, you should see the below output:
*** Booting nRF Connect SDK 2.6.1-3758bcbfa5cd ***[00:00:00.653,900] <inf> main: SAADC buffer at 0x20001150 filled with 8000 samples[00:00:00.653,900] <inf> main: AVG=2064, MIN=2029, MAX=2099[00:00:01.052,673] <inf> main: SAADC buffer at 0x20004fd0 filled with 8000 samples[00:00:01.052,673] <inf> main: AVG=2064, MIN=2025, MAX=2097[00:00:01.451,446] <inf> main: SAADC buffer at 0x20001150 filled with 8000 samples[00:00:01.451,446] <inf> main: AVG=2064, MIN=2028, MAX=2094[00:00:01.850,097] <inf> main: SAADC buffer at 0x20004fd0 filled with 8000 samples[00:00:01.850,128] <inf> main: AVG=2062, MIN=2009, MAX=2100[00:00:02.248,840] <inf> main: SAADC buffer at 0x20001150 filled with 8000 samples[00:00:02.248,870] <inf> main: AVG=2064, MIN=2029, MAX=2103[00:00:02.647,521] <inf> main: SAADC buffer at 0x20004fd0 filled with 8000 samples[00:00:02.647,521] <inf> main: AVG=2064, MIN=2025, MAX=2098
Terminal
Observe that the filled buffer alternates between two different locations, corresponding to the two buffers we have defined.
The solution for this exercise can be found in the course repository, l6/l6_e3_sol.
v3.0.0
In this exercise, we will explore the advanced mode of the SAADC driver to measure voltage source (E.g., a battery) at a high sample rate. We will use a hardware TIMER instance to trigger sampling through DPPI/PPI, without any CPU involvement.
Exercise steps
Open the code base of the exercise by navigating to Create a new application in the nRF Connect for VS Code extension, select Copy a sample, and search for Lesson 6 – Exercise 3.
We also need to enable the TIMER instance that will be used. Available TIMER instances differ between targets. For nRF52/nRF53/nRF91, we will use TIMER2, for nRF54L15, we will use TIMER22. This is done by enabling it in prj.conf:
When building the project, you will see a warning that either PPI or DPPI was assigned the value ‘y’, but got the value ‘n’, depending on which chip you build for. You can ignore this, but it can be resolved by creating separate Kconfig fragment files for the different boards. In this exercise, we have put all Kconfigs in one common prj.conf file for simplicity.
2. Include the nrfx-related header files in the application.
We will use the nrfx SAADC, TIMER and (D)PPI drivers to configure the peripherals.
nRF52 Series chips have a PPI peripheral, while nRF54, nRF53 and nRF91 Series have a more flexible DPPI peripheral. nrfx provides a helper API (nrfx GPPI) that can be used to configure both peripheral variants through a common API. Add nrfx-related header files by including the following lines at the top (include section) of main.c:
3.3 In the function configure_timer(), declare the timer config struct. The parameter passed to NRFX_TIMER_DEFAULT_CONFIG will set the frequency of the timer. The timer config is used to initialize the instance of the timer driver. Since we will use (D)PPI to trigger sampling, no interrupts are needed, and we pass NULL to the event handler parameter:
3.4 We will use the COMPARE0 event from the TIMER to trigger sampling at the interval given by SAADC_SAMPLE_INTERVAL_US. The TIMER will be cleared every time the COMPARE0 event is hit, to create a recurring timer event. Add these lines to the end of the function configure_timer():
4.1 In this example, we will use double buffering, which requires two separate buffers that will be filled with samples sequentially. One buffer will be filled while the other buffer can be processed. Since we have a short sample interval, the buffer needs to be large enough for the CPU to start up and process the previous buffer before the new buffer is filled. Start by defining the buffer size for each of the buffers by adding this line close to the top of main.c:
Copy
#define SAADC_BUFFER_SIZE 8000
C
4.2 Next, let’s declare the two buffers by adding this line below the define section in main.c
4.3 To keep track of which of the two buffers should be assigned to the SAADC driver, we declare a variable corresponding to the current buffer index:
Copy
staticuint32_t saadc_current_buffer = 0;
C
4.4 We will reference the ADC defined in the Zephyr devicetree, to make the code more portable. To connect the SAADC interrupt to SAADC interrupt handler, add these lines in configure_saadc():
By default, the ADC is enabled in the board DTS file for all DKs supported by this course, but for custom boards you may have to enable it in your DTS or overlay file using the following code snippet:
Copy
&adc { status = "okay";};
Devicetree
4.5 Before using the SAADC driver, the driver instance must be initialized. We will again refer to the devicetree to get the configured priority of the ADC node and use this for the driver:
4.6 Declare the struct to hold the configuration for the SAADC channel used to sample the battery voltage. The macro NRFX_SAADC_DEFAULT_CHANNEL_SE() will create the default configuration struct for a single ended input for the provided analog input on channel 0.
The way of configuring pins for SAADC channels have changed for nRF54L15. Chose the tab below that matches your DK.
Connect a battery between GND and analog input (AIN0 or AIN4, depending on your target). Check the Hardware and Layout ->Pin assignment chapter in the Product specification to know which Pin is connected to the analog inputs on your choice of SoC/SiP. You can also connect a jumper wire between analog input 0 and VDD if you do not have a battery available.
4.7 Configure the SAADC channel using the previously defined channel configuration structure. The default configuration uses GAIN=1, which is too high to support supply voltage measurements. We need to change the gain config before configuring the channel:
The GAIN steps are different for nRF54L15 compared to previous SoCs. Chose the tab below that matches with your DK.
4.8 We will use the nrfx SAADC driver in advanced mode on channel 0 for this exercise. It is required to pass a configuration struct to the function, we will use the default defined configuration:
The default configuration disables OVERSAMPLING, BURST, and the internal timer, and it prevents the driver from triggering the START task when END event is generated (when a buffer have been filled). We will later configure triggering of the START task in HW through a (D)PPI channel to make sure there is no delay in buffer switching caused by other SW interrupts preempting the SAADC interrupt handler that would normally handle the buffer swapping. Passing an event handler to the last argument of the function will make the driver operate in non-blocking mode, we will implement the event handler in the next step. Add these lines to configure_saadc():
4.9 The SAADC peripheral can support double buffering by providing a new buffer pointer as soon as the previous buffer has been acquired by the peripheral (STARTED event generated). The SAADC driver can support this feature by calling the buffer set function twice. Call the function once for each of the two previously declared buffers:
5. Implement the event handler for the SAADC driver.
We will now implement the event handler for the SAADC driver, where events passed from the driver will be processed by the application. The available event types are as follows:
In this application, we will not use the limit or calibration features, and since we will use double-buffering, the NRFX_SAADC_EVT_FINISHED event should not happen. The event handler function is declared as saadc_event_handler() in the firmware.
5.1 The NRFX_SAADC_EVT_READY event will trigger when the first buffer has been initialized in the driver and the SAADC is ready for sampling. We will start the timer in this event.
Add this line under the case before the break:
Copy
nrfx_timer_enable(&timer_instance);
C
5.2 The NRFX_SAADC_EVT_BUF_REQ event will be generated whenever a buffer is acquired by the driver, and it can accept a new buffer. We will alternate between the two previously defined buffers and provide the correct one by incrementing a variable (saadc_current_buffer). Add these lines under the case before the break:
5.3 The final event we will handle is the NRFX_SAADC_EVT_DONE event, which is generated when a buffer has been filled with the requested number of samples. Since we are only measuring battery voltage in this example, we will calculate the average, minimum and maximum sample value of all samples in the buffer and output this on the log:
Copy
int64_t average = 0;int16_t max = INT16_MIN;int16_t min = INT16_MAX;int16_t current_value;for (int i = 0; i < p_event->data.done.size; i++) { current_value = ((int16_t *)(p_event->data.done.p_buffer))[i]; average += current_value;if (current_value > max) { max = current_value; }if (current_value < min) { min = current_value; }}average = average / p_event->data.done.size;LOG_INF("SAADC buffer at 0x%x filled with %d samples", (uint32_t)p_event->data.done.p_buffer, p_event->data.done.size);LOG_INF("AVG=%d, MIN=%d, MAX=%d", (int16_t)average, min, max);
C
6. Setup the (D)PPI channels.
Finally, we will setup the (D)PPI channels that will be used to trigger actions automatically in HW, without any CPU interaction.
Trigger SAADC->SAMPLE task based on COMPARE event from timer
Trigger SAADC->START task when SAADC->END event indicates that the buffer is full.
6.1 Declare variables used to hold the (D)PPI channel number. Add these lines to configure_ppi()
6.3 Each (D)PPI channel is assigned to one task and one event endpoint. The endpoints are the register address of the task or event as documented in the Product Specifications of the chip. Most drivers or HAL (Hardware Abstraction Layer) implementation where (D)PPI are relevant have APIs to get the addresses. Setup the first (D)PPI channel from TIMER->COMPARE0 event to trigger SAADC->SAMPLE task:
7. Build the application and flash it to your board.
8. Connect your analog input to a voltage source, just as you did in exercise 1.
This could be a dedicated power supply, a PPK2, a battery, or you can simply connect a wire between the analog input (AIN0) and VDD as shown below.
Note
ake sure that the voltage applied to the analog input does not exceed VDD. If you have a battery with a higher voltage level than VDD, you need to use a voltage divider between the battery and the input.
If you want to measure battery voltage directly from VDD, you can replace NRF_SAADC_INPUT_AIN0 or NRF_SAADC_INPUT_AIN4 (nRF54) with NRF_SAADC_INPUT_VDD.
9. Using a serial terminal, you should see the below output:
*** Booting nRF Connect SDK 2.6.1-3758bcbfa5cd ***[00:00:00.653,900] <inf> main: SAADC buffer at 0x20001150 filled with 8000 samples[00:00:00.653,900] <inf> main: AVG=2064, MIN=2029, MAX=2099[00:00:01.052,673] <inf> main: SAADC buffer at 0x20004fd0 filled with 8000 samples[00:00:01.052,673] <inf> main: AVG=2064, MIN=2025, MAX=2097[00:00:01.451,446] <inf> main: SAADC buffer at 0x20001150 filled with 8000 samples[00:00:01.451,446] <inf> main: AVG=2064, MIN=2028, MAX=2094[00:00:01.850,097] <inf> main: SAADC buffer at 0x20004fd0 filled with 8000 samples[00:00:01.850,128] <inf> main: AVG=2062, MIN=2009, MAX=2100[00:00:02.248,840] <inf> main: SAADC buffer at 0x20001150 filled with 8000 samples[00:00:02.248,870] <inf> main: AVG=2064, MIN=2029, MAX=2103[00:00:02.647,521] <inf> main: SAADC buffer at 0x20004fd0 filled with 8000 samples[00:00:02.647,521] <inf> main: AVG=2064, MIN=2025, MAX=2098
Terminal
Observe that the filled buffer alternates between two different locations, corresponding to the two buffers we have defined.
The solution for this exercise can be found in the course repository, l6/l6_e3_sol.
v3.0.0
In this exercise, we will explore the advanced mode of the SAADC driver to measure voltage source (E.g., a battery) at a high sample rate. We will use a hardware TIMER instance to trigger sampling through DPPI/PPI, without any CPU involvement.
Exercise steps
Open the code base of the exercise by navigating to Create a new application in the nRF Connect for VS Code extension, select Copy a sample, and search for Lesson 6 – Exercise 3.
We also need to enable the TIMER instance that will be used. Available TIMER instances differ between targets. For nRF52/nRF53/nRF91, we will use TIMER2, for nRF54L15, we will use TIMER22. This is done by enabling it in prj.conf:
When building the project, you will see a warning that either PPI or DPPI was assigned the value ‘y’, but got the value ‘n’, depending on which chip you build for. You can ignore this, but it can be resolved by creating separate Kconfig fragment files for the different boards. In this exercise, we have put all Kconfigs in one common prj.conf file for simplicity.
2. Include the nrfx-related header files in the application.
We will use the nrfx SAADC, TIMER and (D)PPI drivers to configure the peripherals.
nRF52 Series chips have a PPI peripheral, while nRF54, nRF53 and nRF91 Series have a more flexible DPPI peripheral. nrfx provides a helper API (nrfx GPPI) that can be used to configure both peripheral variants through a common API. Add nrfx-related header files by including the following lines at the top (include section) of main.c:
3.3 In the function configure_timer(), declare the timer config struct. The parameter passed to NRFX_TIMER_DEFAULT_CONFIG will set the frequency of the timer. The timer config is used to initialize the instance of the timer driver. Since we will use (D)PPI to trigger sampling, no interrupts are needed, and we pass NULL to the event handler parameter:
3.4 We will use the COMPARE0 event from the TIMER to trigger sampling at the interval given by SAADC_SAMPLE_INTERVAL_US. The TIMER will be cleared every time the COMPARE0 event is hit, to create a recurring timer event. Add these lines to the end of the function configure_timer():
4.1 In this example, we will use double buffering, which requires two separate buffers that will be filled with samples sequentially. One buffer will be filled while the other buffer can be processed. Since we have a short sample interval, the buffer needs to be large enough for the CPU to start up and process the previous buffer before the new buffer is filled. Start by defining the buffer size for each of the buffers by adding this line close to the top of main.c:
Copy
#define SAADC_BUFFER_SIZE 8000
C
4.2 Next, let’s declare the two buffers by adding this line below the define section in main.c
4.3 To keep track of which of the two buffers should be assigned to the SAADC driver, we declare a variable corresponding to the current buffer index:
Copy
staticuint32_t saadc_current_buffer = 0;
C
4.4 We will reference the ADC defined in the Zephyr devicetree, to make the code more portable. To connect the SAADC interrupt to SAADC interrupt handler, add these lines in configure_saadc():
By default, the ADC is enabled in the board DTS file for all DKs supported by this course, but for custom boards you may have to enable it in your DTS or overlay file using the following code snippet:
Copy
&adc { status = "okay";};
Devicetree
4.5 Before using the SAADC driver, the driver instance must be initialized. We will again refer to the devicetree to get the configured priority of the ADC node and use this for the driver:
4.6 Declare the struct to hold the configuration for the SAADC channel used to sample the battery voltage. The macro NRFX_SAADC_DEFAULT_CHANNEL_SE() will create the default configuration struct for a single ended input for the provided analog input on channel 0.
The way of configuring pins for SAADC channels have changed for nRF54L15. Chose the tab below that matches your DK.
Connect a battery between GND and analog input (AIN0 or AIN4, depending on your target). Check the Hardware and Layout ->Pin assignment chapter in the Product specification to know which Pin is connected to the analog inputs on your choice of SoC/SiP. You can also connect a jumper wire between analog input 0 and VDD if you do not have a battery available.
4.7 Configure the SAADC channel using the previously defined channel configuration structure. The default configuration uses GAIN=1, which is too high to support supply voltage measurements. We need to change the gain config before configuring the channel:
The GAIN steps are different for nRF54L15 compared to previous SoCs. Chose the tab below that matches with your DK.
4.8 We will use the nrfx SAADC driver in advanced mode on channel 0 for this exercise. It is required to pass a configuration struct to the function, we will use the default defined configuration:
The default configuration disables OVERSAMPLING, BURST, and the internal timer, and it prevents the driver from triggering the START task when END event is generated (when a buffer have been filled). We will later configure triggering of the START task in HW through a (D)PPI channel to make sure there is no delay in buffer switching caused by other SW interrupts preempting the SAADC interrupt handler that would normally handle the buffer swapping. Passing an event handler to the last argument of the function will make the driver operate in non-blocking mode, we will implement the event handler in the next step. Add these lines to configure_saadc():
4.9 The SAADC peripheral can support double buffering by providing a new buffer pointer as soon as the previous buffer has been acquired by the peripheral (STARTED event generated). The SAADC driver can support this feature by calling the buffer set function twice. Call the function once for each of the two previously declared buffers:
5. Implement the event handler for the SAADC driver.
We will now implement the event handler for the SAADC driver, where events passed from the driver will be processed by the application. The available event types are as follows:
In this application, we will not use the limit or calibration features, and since we will use double-buffering, the NRFX_SAADC_EVT_FINISHED event should not happen. The event handler function is declared as saadc_event_handler() in the firmware.
5.1 The NRFX_SAADC_EVT_READY event will trigger when the first buffer has been initialized in the driver and the SAADC is ready for sampling. We will start the timer in this event.
Add this line under the case before the break:
Copy
nrfx_timer_enable(&timer_instance);
C
5.2 The NRFX_SAADC_EVT_BUF_REQ event will be generated whenever a buffer is acquired by the driver, and it can accept a new buffer. We will alternate between the two previously defined buffers and provide the correct one by incrementing a variable (saadc_current_buffer). Add these lines under the case before the break:
5.3 The final event we will handle is the NRFX_SAADC_EVT_DONE event, which is generated when a buffer has been filled with the requested number of samples. Since we are only measuring battery voltage in this example, we will calculate the average, minimum and maximum sample value of all samples in the buffer and output this on the log:
Copy
int64_t average = 0;int16_t max = INT16_MIN;int16_t min = INT16_MAX;int16_t current_value;for (int i = 0; i < p_event->data.done.size; i++) { current_value = ((int16_t *)(p_event->data.done.p_buffer))[i]; average += current_value;if (current_value > max) { max = current_value; }if (current_value < min) { min = current_value; }}average = average / p_event->data.done.size;LOG_INF("SAADC buffer at 0x%x filled with %d samples", (uint32_t)p_event->data.done.p_buffer, p_event->data.done.size);LOG_INF("AVG=%d, MIN=%d, MAX=%d", (int16_t)average, min, max);
C
6. Setup the (D)PPI channels.
Finally, we will setup the (D)PPI channels that will be used to trigger actions automatically in HW, without any CPU interaction.
Trigger SAADC->SAMPLE task based on COMPARE event from timer
Trigger SAADC->START task when SAADC->END event indicates that the buffer is full.
6.1 Declare variables used to hold the (D)PPI channel number. Add these lines to configure_ppi()
6.3 Each (D)PPI channel is assigned to one task and one event endpoint. The endpoints are the register address of the task or event as documented in the Product Specifications of the chip. Most drivers or HAL (Hardware Abstraction Layer) implementation where (D)PPI are relevant have APIs to get the addresses. Setup the first (D)PPI channel from TIMER->COMPARE0 event to trigger SAADC->SAMPLE task:
7. Build the application and flash it to your board.
8. Connect your analog input to a voltage source, just as you did in exercise 1.
This could be a dedicated power supply, a PPK2, a battery, or you can simply connect a wire between the analog input (AIN0) and VDD as shown below.
Note
ake sure that the voltage applied to the analog input does not exceed VDD. If you have a battery with a higher voltage level than VDD, you need to use a voltage divider between the battery and the input.
If you want to measure battery voltage directly from VDD, you can replace NRF_SAADC_INPUT_AIN0 or NRF_SAADC_INPUT_AIN4 (nRF54) with NRF_SAADC_INPUT_VDD.
9. Using a serial terminal, you should see the below output:
*** Booting nRF Connect SDK 2.6.1-3758bcbfa5cd ***[00:00:00.653,900] <inf> main: SAADC buffer at 0x20001150 filled with 8000 samples[00:00:00.653,900] <inf> main: AVG=2064, MIN=2029, MAX=2099[00:00:01.052,673] <inf> main: SAADC buffer at 0x20004fd0 filled with 8000 samples[00:00:01.052,673] <inf> main: AVG=2064, MIN=2025, MAX=2097[00:00:01.451,446] <inf> main: SAADC buffer at 0x20001150 filled with 8000 samples[00:00:01.451,446] <inf> main: AVG=2064, MIN=2028, MAX=2094[00:00:01.850,097] <inf> main: SAADC buffer at 0x20004fd0 filled with 8000 samples[00:00:01.850,128] <inf> main: AVG=2062, MIN=2009, MAX=2100[00:00:02.248,840] <inf> main: SAADC buffer at 0x20001150 filled with 8000 samples[00:00:02.248,870] <inf> main: AVG=2064, MIN=2029, MAX=2103[00:00:02.647,521] <inf> main: SAADC buffer at 0x20004fd0 filled with 8000 samples[00:00:02.647,521] <inf> main: AVG=2064, MIN=2025, MAX=2098
Terminal
Observe that the filled buffer alternates between two different locations, corresponding to the two buffers we have defined.
The solution for this exercise can be found in the course repository, l6/l6_e3_sol.
Nordic Developer Academy Privacy Policy
1. Introduction
In this Privacy Policy you will find information on Nordic Semiconductor ASA (“Nordic Semiconductor”) processes your personal data when you use the Nordic Developer Academy.
References to “we” and “us” in this document refers to Nordic Semiconductor.
2. Our processing of personal data when you use the Nordic Developer Academy
2.1 Nordic Developer Academy
Nordic Semiconductor processes personal data in order to provide you with the features and functionality of the Nordic Developer Academy. Creating a user account is optional, but required if you want to track you progress and view your completed courses and obtained certificates. If you choose to create a user account, we will process the following categories of personal data:
Email
Name
Password (encrypted)
Course progression (e.g. which course you have completely or partly completed)
Certificate information, which consists of name of completed course and the validity of the certificate
Course results
During your use of the Nordic Developer Academy, you may also be asked if you want to provide feedback. If you choose to respond to any such surveys, we will also process the personal data in your responses in that survey.
The legal basis for this processing is GDPR article 6 (1) b. The processing is necessary for Nordic Semiconductor to provide the Nordic Developer Academy under the Terms of Service.
2.2 Analytics
If you consent to analytics, Nordic Semiconductor will use Google Analytics to obtain statistics about how the Nordic Developer Academy is used. This includes collecting information on for example what pages are viewed, the duration of the visit, the way in which the pages are maneuvered, what links are clicked, technical information about your equipment. The information is used to learn how Nordic Developer Academy is used and how the user experience can be further developed.
2.2 Newsletter
You can consent to receive newsletters from Nordic from within the Nordic Developer Academy. How your personal data is processed when you sign up for our newsletters is described in the Nordic Semiconductor Privacy Policy.
3. Retention period
We will store your personal data for as long you use the Nordic Developer Academy. If our systems register that you have not used your account for 36 months, your account will be deleted.
4. Additional information
Additional information on how we process personal data can be found in the Nordic Semiconductor Privacy Policy and Cookie Policy.
Nordic Developer Academy Terms of Service
1. Introduction
These terms and conditions (“Terms of Use”) apply to the use of the Nordic Developer Academy, provided by Nordic Semiconductor ASA, org. nr. 966 011 726, a public limited liability company registered in Norway (“Nordic Semiconductor”).
Nordic Developer Academy allows the user to take technical courses related to Nordic Semiconductor products, software and services, and obtain a certificate certifying completion of these courses. By completing the registration process for the Nordic Developer Academy, you are agreeing to be bound by these Terms of Use.
These Terms of Use are applicable as long as you have a user account giving you access to Nordic Developer Academy.
2. Access to and use of Nordic Developer Academy
Upon acceptance of these Terms of Use you are granted a non-exclusive right of access to, and use of Nordic Developer Academy, as it is provided to you at any time. Nordic Semiconductor provides Nordic Developer Academy to you free of charge, subject to the provisions of these Terms of Use and the Nordic Developer Academy Privacy Policy.
To access select features of Nordic Developer Academy, you need to create a user account. You are solely responsible for the security associated with your user account, including always keeping your login details safe.
You will able to receive an electronic certificate from Nordic Developer Academy upon completion of courses. By issuing you such a certificate, Nordic Semiconductor certifies that you have completed the applicable course, but does not provide any further warrants or endorsements for any particular skills or professional qualifications.
Nordic Semiconductor will continuously develop Nordic Developer Academy with new features and functionality, but reserves the right to remove or alter any existing functions without notice.
3. Acceptable use
You undertake that you will use Nordic Developer Academy in accordance with applicable law and regulations, and in accordance with these Terms of Use. You must not modify, adapt, or hack Nordic Developer Academy or modify another website so as to falsely imply that it is associated with Nordic Developer Academy, Nordic Semiconductor, or any other Nordic Semiconductor product, software or service.
You agree not to reproduce, duplicate, copy, sell, resell or in any other way exploit any portion of Nordic Developer Academy, use of Nordic Developer Academy, or access to Nordic Developer Academy without the express written permission by Nordic Semiconductor. You must not upload, post, host, or transmit unsolicited email, SMS, or \”spam\” messages.
You are responsible for ensuring that the information you post and the content you share does not;
contain false, misleading or otherwise erroneous information
infringe someone else’s copyrights or other intellectual property rights
contain sensitive personal data or
contain information that might be received as offensive or insulting.
Such information may be removed without prior notice.
Nordic Semiconductor reserves the right to at any time determine whether a use of Nordic Developer Academy is in violation of its requirements for acceptable use.
Violation of the at any time applicable requirements for acceptable use may result in termination of your account. We will take reasonable steps to notify you and state the reason for termination in such cases.
4. Routines for planned maintenance
Certain types of maintenance may imply a stop or reduction in availability of Nordic Developer Academy. Nordic Semiconductor does not warrant any level of service availability but will provide its best effort to limit the impact of any planned maintenance on the availability of Nordic Developer Academy.
5. Intellectual property rights
Nordic Semiconductor retains all rights to all elements of Nordic Developer Academy. This includes, but is not limited to, the concept, design, trademarks, know-how, trade secrets, copyrights and all other intellectual property rights.
Nordic Semiconductor receives all rights to all content uploaded or created in Nordic Developer Academy. You do not receive any license or usage rights to Nordic Developer Academy beyond what is explicitly stated in this Agreement.
6. Liability and damages
Nothing within these Terms of Use is intended to limit your statutory data privacy rights as a data subject, as described in the Nordic Developer Academy Privacy Policy. You acknowledge that errors might occur from time to time and waive any right to claim for compensation as a result of errors in Nordic Developer Academy. When an error occurs, you shall notify Nordic Semiconductor of the error and provide a description of the error situation.
You agree to indemnify Nordic Semiconductor for any loss, including indirect loss, arising out of or in connection with your use of Nordic Developer Academy or violations of these Terms of Use. Nordic Semiconductor shall not be held liable for, and does not warrant that (i) Nordic Developer Academy will meet your specific requirements, (ii) Nordic Developer Academy will be uninterrupted, timely, secure, or error-free, (iii) the results that may be obtained from the use of Nordic Developer Academy will be accurate or reliable, (iv) the quality of any products, services, information, or other material purchased or obtained by you through Nordic Developer Academy will meet your expectations, or that (v) any errors in Nordic Developer Academy will be corrected.
You accept that this is a service provided to you without any payment and hence you accept that Nordic Semiconductor will not be held responsible, or liable, for any breaches of these Terms of Use or any loss connected to your use of Nordic Developer Academy. Unless otherwise follows from mandatory law, Nordic Semiconductor will not accept any such responsibility or liability.
7. Change of terms
Nordic Semiconductor may update and change the Terms of Use from time to time. Nordic Semiconductor will seek to notify you about significant changes before such changes come into force and give you a possibility to evaluate the effects of proposed changes. Continued use of Nordic Developer Academy after any such changes shall constitute your acceptance of such changes. You can review the current version of the Terms of Use at any time at https://academy.nordicsemi.com/terms-of-service/
8. Transfer of rights
Nordic Semiconductor is entitled to transfer its rights and obligation pursuant to these Terms of Use to a third party as part of a merger or acquisition process, or as a result of other organizational changes.
9. Third Party Services
To the extent Nordic Developer Academy facilitates access to services provided by a third party, you agree to comply with the terms governing such third party services. Nordic Semiconductor shall not be held liable for any errors, omissions, inaccuracies, etc. related to such third party services.
10. Dispute resolution
The Terms of Use and any other legally binding agreement between yourself and Nordic Semiconductor shall be subject to Norwegian law and Norwegian courts’ exclusive jurisdiction.