File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed
examples/PDMSerialPlotter Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ volatile int samplesRead;
18
18
19
19
void setup () {
20
20
Serial.begin (9600 );
21
- while (!Serial);
21
+ while (!Serial) yield () ;
22
22
23
23
// configure the data receive callback
24
24
PDM.onReceive (onPDMdata);
@@ -31,7 +31,7 @@ void setup() {
31
31
// - a 16 kHz sample rate
32
32
if (!PDM.begin (1 , 16000 )) {
33
33
Serial.println (" Failed to start PDM!" );
34
- while (1 );
34
+ while (1 ) yield () ;
35
35
}
36
36
}
37
37
Original file line number Diff line number Diff line change @@ -58,9 +58,29 @@ int PDMClass::begin(int channels, long sampleRate)
58
58
_channels = channels;
59
59
60
60
// Enable high frequency oscillator if not already enabled
61
- if (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0 ) {
62
- NRF_CLOCK->TASKS_HFCLKSTART = 1 ;
63
- while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0 ) { }
61
+ uint8_t sd_en = 0 ;
62
+ sd_softdevice_is_enabled (&sd_en);
63
+
64
+ if (sd_en)
65
+ {
66
+ uint32_t is_running;
67
+ sd_clock_hfclk_is_running (&is_running);
68
+
69
+ if (!is_running) {
70
+ sd_clock_hfclk_request ();
71
+
72
+ while (!is_running) {
73
+ yield ();
74
+ sd_clock_hfclk_is_running (&is_running);
75
+ }
76
+ }
77
+ }
78
+ else
79
+ {
80
+ if (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0 ) {
81
+ NRF_CLOCK->TASKS_HFCLKSTART = 1 ;
82
+ while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0 ) yield ();
83
+ }
64
84
}
65
85
66
86
// configure the sample rate and channels
You can’t perform that action at this time.
0 commit comments