Skip to content

Commit 1915312

Browse files
committed
- Now uses LoRa.receive(): Much better as the versions before since the DIO0 is used again.
- Cleaned up wrong use of wdt.h constants.
1 parent 2b77ae7 commit 1915312

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

examples/LoRaReceiverCadDemo328pDIO0/LoRaReceiverCadDemo328pDIO0.ino

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ void setup() {
3535
WDTCSR |= 1<<WDCE | 1<<WDE;
3636

3737
// Table 10-3. Watchdog Timer Prescale Select
38-
//WDTCSR = WDTO_8S; // 1<<WDP3 | 1<<WDP0; // 8 seconds
39-
//WDTCSR = WDTO_4S; // 1<<WDP3; // 4 seconds
40-
//WDTCSR = WDTO_2S; // 1<<WDP2 | 1<<WDP1 | 1<<WDP0; // 2 seconds
41-
//WDTCSR = WDTO_1S; // 1<<WDP2 | 1<<WDP1; // 1 seconds
42-
//WDTCSR = WDTO_30MS;
43-
WDTCSR = WDTO_15MS;
38+
//WDTCSR = 1<<WDP3 | 1<<WDP0; // 8 seconds
39+
//WDTCSR = 1<<WDP3; // 4 seconds
40+
//WDTCSR = 1<<WDP2 | 1<<WDP1 | 1<<WDP0; // 2 seconds
41+
//WDTCSR = 1<<WDP2 | 1<<WDP1; // 1 seconds
42+
//WDTCSR = 1<<WDP0; // 32 ms
43+
WDTCSR = 0; // 16 ms
4444

4545
WDTCSR |= 1<<WDIE;
4646

@@ -121,24 +121,20 @@ void loop() {
121121
// dio1 is not used in this sketch: CadDetected is looked up in RegIrqFlags
122122

123123
if (LoRa.irqCadDetected()){
124-
// prepare radio to receive a single packet
125-
// no need to change DIO mapping in this sketch, run parsePacket() instead
126-
// manually change state (previously it was changed in setRxSingle())
124+
LoRa.receive();
125+
127126
// these attributes are not really needed in this sketch anymore
128127
LoRa.cadModeActive = false;
129-
LoRa.rxSingleMode = true;
130-
131-
// when not already in RxSingle, LoRa.parsePacket() first sets the radio in RxSingle
132-
LoRa.parsePacket();
133-
134-
// wait a while for the packet to arrive
135-
go_to_sleep();
136-
137-
uint32_t read_timeout = millis() + 200;
138-
while (millis() < read_timeout){
139-
if (parse_packet()){
128+
//LoRa.rxSingleMode = true;
129+
130+
// sleep a while until RxDone is triggered
131+
for (uint8_t i = 0; i < 20; i++){
132+
go_to_sleep();
133+
if (dio0_rise){
134+
dio0_rise = false;
135+
parse_packet();
140136
Serial.flush();
141-
break;
137+
break;
142138
}
143139
}
144140

0 commit comments

Comments
 (0)