Pathfindr / Mbed OS mbed-os-PF-UWBBEACON_v1_dev

Dependencies:   aconno_I2C Lis2dh12 WatchdogTimer

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers acd_nrf52_saadc.cpp Source File

acd_nrf52_saadc.cpp

00001 #include "acd_nrf52_saadc.h"
00002 
00003 // add and remove analog channels -> +/- maxcnt
00004 
00005 NRF52_SAADC::NRF52_SAADC(){
00006     NRF_SAADC->ENABLE = 1;
00007     memset(data, 0, sizeof(data));
00008     NRF_SAADC->RESULT.PTR =(uint32_t)data;
00009     NRF_SAADC->RESULT.MAXCNT = 0;
00010 }
00011 
00012 NRF52_SAADC::~NRF52_SAADC(){
00013     NRF_SAADC->ENABLE = 0;
00014 }
00015 
00016 void NRF52_SAADC::updateData(){
00017     NRF_SAADC->TASKS_START = 1;
00018     while(!NRF_SAADC->EVENTS_STARTED);
00019     NRF_SAADC->TASKS_SAMPLE = 1;
00020     for(uint8_t i = 0; i < NRF_SAADC->RESULT.MAXCNT; ++i)
00021     {
00022         while(!NRF_SAADC->EVENTS_RESULTDONE);
00023         while(!NRF_SAADC->EVENTS_DONE);
00024         while(!NRF_SAADC->EVENTS_END);
00025         while(NRF_SAADC->STATUS == 1); // while conversion is is progress
00026     }
00027     NRF_SAADC->TASKS_STOP = 1;
00028     while(!NRF_SAADC->EVENTS_STOPPED);
00029 }
00030 
00031 bool NRF52_SAADC::addChannel (uint8_t pin){
00032     if(NRF_SAADC->RESULT.MAXCNT < 8)
00033     {
00034         int channel = NRF_SAADC->RESULT.MAXCNT;
00035         NRF_SAADC->CH[channel].PSELP = pin;     // Input positive pin is VDD = 9
00036         NRF_SAADC->CH[channel].CONFIG = 0x00020000; // reset
00037         NRF_SAADC->RESULT.MAXCNT++;
00038         return 0;
00039     }
00040     return 1;
00041 }
00042 
00043 void NRF52_SAADC::calibrate(){
00044     NRF_SAADC->TASKS_CALIBRATEOFFSET = 1;
00045     while(!NRF_SAADC->EVENTS_CALIBRATEDONE);
00046 }