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.
Dependents: acd52832_SAADC_Differential_input_2
Fork of acn_nrf52_saadc by
Diff: acd_nrf52_saadc.cpp
- Revision:
- 3:fcada8b3b567
- Parent:
- 2:1e7d6ab5b04b
- Child:
- 4:616c6590bbd2
--- a/acd_nrf52_saadc.cpp Wed Aug 23 07:59:02 2017 +0000
+++ b/acd_nrf52_saadc.cpp Wed Aug 23 08:49:09 2017 +0000
@@ -2,20 +2,18 @@
// add and remove analog channels -> +/- maxcnt
-NRF52_SAADC::NRF52_SAADC(int16_t *dataPointer) : dataPointer(dataPointer){
+NRF52_SAADC::NRF52_SAADC(){
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
- NRF_SAADC->TASKS_CALIBRATEOFFSET = 1;
- while(!NRF_SAADC->EVENTS_CALIBRATEDONE);
+ memset(data, 0, sizeof(data));
+ NRF_SAADC->RESULT.PTR =(uint32_t)data;
+ NRF_SAADC->RESULT.MAXCNT = 0;
}
NRF52_SAADC::~NRF52_SAADC(){
NRF_SAADC->ENABLE = 0;
}
-void NRF52_SAADC::getData(){
+void NRF52_SAADC::updateData(){
NRF_SAADC->TASKS_START = 1;
while(!NRF_SAADC->EVENTS_STARTED);
NRF_SAADC->TASKS_SAMPLE = 1;
@@ -23,6 +21,23 @@
while(!NRF_SAADC->EVENTS_DONE);
while(!NRF_SAADC->EVENTS_END);
while(NRF_SAADC->STATUS == 1); // while conversion is is progress
- NRF_SAADC->TASKS_STOP = 1;
- while(!NRF_SAADC->EVENTS_STOPPED);
+ //NRF_SAADC->TASKS_STOP = 1;
+ //while(!NRF_SAADC->EVENTS_STOPPED);
}
+
+bool NRF52_SAADC::addChannel(uint8_t pin){
+ if(NRF_SAADC->RESULT.MAXCNT < 8)
+ {
+ int channel = NRF_SAADC->RESULT.MAXCNT;
+ NRF_SAADC->CH[channel].PSELP = pin; // Input positive pin is VDD = 9
+ NRF_SAADC->CH[channel].CONFIG = 0x00020000; // reset
+ NRF_SAADC->RESULT.MAXCNT++;
+ return 0;
+ }
+ return 1;
+}
+
+void NRF52_SAADC::calibrate(){
+ NRF_SAADC->TASKS_CALIBRATEOFFSET = 1;
+ while(!NRF_SAADC->EVENTS_CALIBRATEDONE);
+}
\ No newline at end of file
