Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: aconno_I2C Lis2dh12 WatchdogTimer
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 }
Generated on Sat Jul 16 2022 03:03:28 by
1.7.2