SAADC library and drivers for nrf52832.

Dependents:   acd52832_SAADC_Differential_input_EPD acd52832_Car_battery_ch acd52832_Car_battery_ch_2

Library to use aconno drivers for Nordic Semiconductor nrf52832 SAADC.

acd_nrf52_saadc.cpp

Committer:
Dautor
Date:
2017-08-23
Revision:
1:2d6e904c6843
Parent:
0:838e26b2ef09
Child:
2:1e7d6ab5b04b

File content as of revision 1:2d6e904c6843:

#include "acd_nrf52_saadc.h"

// add and remove analog channels -> +/- maxcnt

NRF52_SAADC::NRF52_SAADC(int16_t *dataPointer) : dataPointer(dataPointer){
    NRF_SAADC->ENABLE = 1;
    NRF_SAADC->RESULT.MAXCNT = 1;
    NRF_SAADC->RESULT.PTR =(uint32_t)dataPointer;
    NRF_SAADC->CH[0].PSELP = 9;     // Input positive pin is VDD = 9
}

NRF52_SAADC::~NRF52_SAADC(){
    
}

void NRF52_SAADC::getData(){
    NRF_SAADC->TASKS_START = 1;
    while(!NRF_SAADC->EVENTS_STARTED);
    NRF_SAADC->TASKS_SAMPLE = 1;
    while(!NRF_SAADC->EVENTS_END);
    while(!NRF_SAADC->EVENTS_RESULTDONE);
    while(!NRF_SAADC->EVENTS_DONE);
    //if(NRF_SAADC->RESULT.AMOUNT == 0);
    wait_us(20);
    NRF_SAADC->TASKS_STOP = 1;
    while(!NRF_SAADC->EVENTS_STOPPED);
}