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;
1818
1919void setup () {
2020 Serial.begin (9600 );
21- while (!Serial);
21+ while (!Serial) yield () ;
2222
2323 // configure the data receive callback
2424 PDM.onReceive (onPDMdata);
@@ -31,7 +31,7 @@ void setup() {
3131 // - a 16 kHz sample rate
3232 if (!PDM.begin (1 , 16000 )) {
3333 Serial.println (" Failed to start PDM!" );
34- while (1 );
34+ while (1 ) yield () ;
3535 }
3636}
3737
Original file line number Diff line number Diff line change @@ -58,9 +58,29 @@ int PDMClass::begin(int channels, long sampleRate)
5858 _channels = channels;
5959
6060 // 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+ }
6484 }
6585
6686 // configure the sample rate and channels
You can’t perform that action at this time.
0 commit comments