Hi, for some reason ADC_IRQHandler is never called for me.
It's fairly simple and a direct copy of the battery sensor example, so not sure what happened here. is there any board config magic i need maybe to enable ADCs?
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "nrf_soc.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "boards.h"
#include "simple_uart.h"
#define SOILSENS_READ 17
#define SOILSENS_POWER 18
#define GPIO_SENSOR_DATA 19
void ADC_IRQHandler(void)
{
simple_uart_putstring((const uint8_t *)"ADC_IRQHandler\r\n");
uint16_t adc_result = 0;
if (NRF_ADC->EVENTS_END != 0) {
adc_result = NRF_ADC->RESULT;
NRF_ADC->TASKS_STOP = 1;
char buffer[12];
sprintf(buffer, "%i\r\n", adc_result);
simple_uart_putstring((const uint8_t *)buffer);
}
}
void adc_start(int analogInputPin)
{
NRF_ADC->INTENSET = ADC_INTENSET_END_Msk;
NRF_ADC->CONFIG =
(ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos) |
(ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) |
(ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) |
(analogInputPin << ADC_CONFIG_PSEL_Pos) |
(ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos);
NRF_ADC->EVENTS_END = 0;
NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
sd_nvic_ClearPendingIRQ(ADC_IRQn);
sd_nvic_SetPriority(ADC_IRQn, NRF_APP_PRIORITY_LOW);
sd_nvic_EnableIRQ(ADC_IRQn);
NRF_ADC->EVENTS_END = 0;
NRF_ADC->TASKS_START = 1;
}
int main(void)
{
simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, 0);
nrf_gpio_cfg_output(SOILSENS_POWER);
nrf_gpio_pin_set(SOILSENS_POWER);
nrf_gpio_cfg_input(SOILSENS_READ, NRF_GPIO_PIN_PULLDOWN);
while (true)
{
simple_uart_putstring((const uint8_t *)"Start:\r\n");
adc_start(SOILSENS_READ);
nrf_delay_ms(500);
continue;
}
}