Skip to content

Commit 48d154c

Browse files
authored
Merge pull request matthijskooijman#160 from manuelbl/issue38
Fix matthijskooijman#38: Properly initialize NSS, RXTX, RST pins
2 parents aa1b263 + bea7e9e commit 48d154c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/hal/hal.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,19 @@ static void hal_io_init () {
3333
// Serial.print("dio[1]: "); Serial.println(plmic_pins->dio[1]);
3434
// Serial.print("dio[2]: "); Serial.println(plmic_pins->dio[2]);
3535

36+
// initialize SPI chip select to high (it's active low)
37+
digitalWrite(plmic_pins->nss, HIGH);
3638
pinMode(plmic_pins->nss, OUTPUT);
37-
if (plmic_pins->rxtx != LMIC_UNUSED_PIN)
39+
40+
if (plmic_pins->rxtx != LMIC_UNUSED_PIN) {
41+
// initialize to RX
42+
digitalWrite(plmic_pins->rxtx, LOW != plmic_pins->rxtx_rx_active);
3843
pinMode(plmic_pins->rxtx, OUTPUT);
39-
if (plmic_pins->rst != LMIC_UNUSED_PIN)
40-
pinMode(plmic_pins->rst, OUTPUT);
44+
}
45+
if (plmic_pins->rst != LMIC_UNUSED_PIN) {
46+
// initialize RST to floating
47+
pinMode(plmic_pins->rst, INPUT);
48+
}
4149

4250
hal_interrupt_init();
4351
}
@@ -54,8 +62,8 @@ void hal_pin_rst (u1_t val) {
5462
return;
5563

5664
if(val == 0 || val == 1) { // drive pin
57-
pinMode(plmic_pins->rst, OUTPUT);
5865
digitalWrite(plmic_pins->rst, val);
66+
pinMode(plmic_pins->rst, OUTPUT);
5967
} else { // keep pin floating
6068
pinMode(plmic_pins->rst, INPUT);
6169
}

0 commit comments

Comments
 (0)