Skip to content

Commit 6e97004

Browse files
authored
Merge pull request #677 from adafruit/fix-pdm
fix pdm issue when bluefruit is enabled
2 parents 83c21dc + f5ceb93 commit 6e97004

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

libraries/PDM/examples/PDMSerialPlotter/PDMSerialPlotter.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ volatile int samplesRead;
1818

1919
void 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

libraries/PDM/src/PDM.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)