Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5551ed

Browse files
committed
fixing analogRead freeze problem + fixing indentation
Sample end flag should be set before starting A-D, otherwise it might can an infinite loop See -http://forum.rfduino.com/index.php?topic=1012.0
1 parent 24542d0 commit c5551ed

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cores/arduino/wiring_analog.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ uint32_t analogRead(uint32_t ulPin)
109109
(analog_reference << ADC_CONFIG_REFSEL_Pos)| // DEFAULT: Use supply voltage with 1/3 prescaling as reference for conversion. Only usable when supply voltage is between 2.5V and 3.6V
110110
(pselValue << ADC_CONFIG_PSEL_Pos)| // Select ADC input
111111
(ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos);
112-
NRF_ADC->INTENCLR = 0xFFFFFFFF;
113-
NRF_ADC->ENABLE = (ADC_ENABLE_ENABLE_Enabled << ADC_ENABLE_ENABLE_Pos); // Enable ADC
114-
NRF_ADC->TASKS_START = 1; // Start A-D conversion
115-
NRF_ADC->EVENTS_END = 0;
112+
NRF_ADC->INTENCLR = 0xFFFFFFFF;
113+
NRF_ADC->ENABLE = (ADC_ENABLE_ENABLE_Enabled << ADC_ENABLE_ENABLE_Pos); // Enable ADC
114+
NRF_ADC->EVENTS_END = 0; // Reset end flag
115+
NRF_ADC->TASKS_START = 1; // Start A-D conversion
116116
while (! NRF_ADC->EVENTS_END) // Wait for end of conversion
117117
;
118118
ulValue = NRF_ADC->RESULT; // Read the value

0 commit comments

Comments
 (0)