init

Dependencies:   aconno_I2C Lis2dh12 WatchdogTimer

Committer:
pathfindr
Date:
Mon Feb 17 23:24:52 2020 +0000
Revision:
58:8d4a354816b1
Parent:
14:9a54b1b65bc8
usb

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pathfindr 14:9a54b1b65bc8 1 #include "acd_nrf52_saadc.h"
pathfindr 14:9a54b1b65bc8 2
pathfindr 14:9a54b1b65bc8 3 // add and remove analog channels -> +/- maxcnt
pathfindr 14:9a54b1b65bc8 4
pathfindr 14:9a54b1b65bc8 5 NRF52_SAADC::NRF52_SAADC(){
pathfindr 14:9a54b1b65bc8 6 NRF_SAADC->ENABLE = 1;
pathfindr 14:9a54b1b65bc8 7 memset(data, 0, sizeof(data));
pathfindr 14:9a54b1b65bc8 8 NRF_SAADC->RESULT.PTR =(uint32_t)data;
pathfindr 14:9a54b1b65bc8 9 NRF_SAADC->RESULT.MAXCNT = 0;
pathfindr 14:9a54b1b65bc8 10 }
pathfindr 14:9a54b1b65bc8 11
pathfindr 14:9a54b1b65bc8 12 NRF52_SAADC::~NRF52_SAADC(){
pathfindr 14:9a54b1b65bc8 13 NRF_SAADC->ENABLE = 0;
pathfindr 14:9a54b1b65bc8 14 }
pathfindr 14:9a54b1b65bc8 15
pathfindr 14:9a54b1b65bc8 16 void NRF52_SAADC::updateData(){
pathfindr 14:9a54b1b65bc8 17 NRF_SAADC->TASKS_START = 1;
pathfindr 14:9a54b1b65bc8 18 while(!NRF_SAADC->EVENTS_STARTED);
pathfindr 14:9a54b1b65bc8 19 NRF_SAADC->TASKS_SAMPLE = 1;
pathfindr 14:9a54b1b65bc8 20 for(uint8_t i = 0; i < NRF_SAADC->RESULT.MAXCNT; ++i)
pathfindr 14:9a54b1b65bc8 21 {
pathfindr 14:9a54b1b65bc8 22 while(!NRF_SAADC->EVENTS_RESULTDONE);
pathfindr 14:9a54b1b65bc8 23 while(!NRF_SAADC->EVENTS_DONE);
pathfindr 14:9a54b1b65bc8 24 while(!NRF_SAADC->EVENTS_END);
pathfindr 14:9a54b1b65bc8 25 while(NRF_SAADC->STATUS == 1); // while conversion is is progress
pathfindr 14:9a54b1b65bc8 26 }
pathfindr 14:9a54b1b65bc8 27 NRF_SAADC->TASKS_STOP = 1;
pathfindr 14:9a54b1b65bc8 28 while(!NRF_SAADC->EVENTS_STOPPED);
pathfindr 14:9a54b1b65bc8 29 }
pathfindr 14:9a54b1b65bc8 30
pathfindr 14:9a54b1b65bc8 31 bool NRF52_SAADC::addChannel(uint8_t pin){
pathfindr 14:9a54b1b65bc8 32 if(NRF_SAADC->RESULT.MAXCNT < 8)
pathfindr 14:9a54b1b65bc8 33 {
pathfindr 14:9a54b1b65bc8 34 int channel = NRF_SAADC->RESULT.MAXCNT;
pathfindr 14:9a54b1b65bc8 35 NRF_SAADC->CH[channel].PSELP = pin; // Input positive pin is VDD = 9
pathfindr 14:9a54b1b65bc8 36 NRF_SAADC->CH[channel].CONFIG = 0x00020000; // reset
pathfindr 14:9a54b1b65bc8 37 NRF_SAADC->RESULT.MAXCNT++;
pathfindr 14:9a54b1b65bc8 38 return 0;
pathfindr 14:9a54b1b65bc8 39 }
pathfindr 14:9a54b1b65bc8 40 return 1;
pathfindr 14:9a54b1b65bc8 41 }
pathfindr 14:9a54b1b65bc8 42
pathfindr 14:9a54b1b65bc8 43 void NRF52_SAADC::calibrate(){
pathfindr 14:9a54b1b65bc8 44 NRF_SAADC->TASKS_CALIBRATEOFFSET = 1;
pathfindr 14:9a54b1b65bc8 45 while(!NRF_SAADC->EVENTS_CALIBRATEDONE);
pathfindr 14:9a54b1b65bc8 46 }