Advertisement
Guest User

adc10_data_get

a guest
Jun 22nd, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. static uint16_t adc10_data_get(void)
  2. {
  3. uint16_t adc_read;
  4.  
  5. NRF_ADC->INTENSET= 0; // disable interrupt
  6. NRF_ADC->EVENTS_END = 0;
  7. NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled; // Enable ADC
  8. NRF_ADC->CONFIG = (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos) /* Bits 17..16 : ADC external reference pin selection. */
  9. | (ADC_CONFIG_PSEL_AnalogInput5 << ADC_CONFIG_PSEL_Pos) /*!< Use analog input X as analog input. */
  10. | (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) /*!< Use internal 1.2V bandgap voltage as reference for conversion. */
  11. | (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) /*!< Analog input specified by PSEL with prescaling used as input for the conversion. */
  12. | (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos); /*!< 10bit ADC resolution. */
  13. NRF_ADC->TASKS_START = 1; //Start ADC sampling
  14. while (!NRF_ADC->EVENTS_END) {} // wait till ADC sampling finishes
  15. NRF_ADC->EVENTS_END = 0;
  16. adc_read = NRF_ADC->RESULT; // read ADC result
  17. NRF_ADC->TASKS_STOP = 1; //Use the STOP task to save current. Workaround for PAN_028 rev1.5 anomaly 1.
  18. return adc_read;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement