Skip to content

Commit cd0df70

Browse files
torntrouserssandeepmistry
authored andcommitted
Issue 85 setting ldo flag (#121)
* Add getting the frequency error of a packet * Update for review comments * Add functions to set low data rate optimization flag * Typo * Fixes * Add packetFrequencyError to API.md * WIP * Simplify * Make getSpreadingFactor private * Correct LDO bit calculation * Update LDO determination * Correct calculation * Correct calculation * Revert back to old LDO calculation
1 parent 5d6a7a3 commit cd0df70

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

src/LoRa.cpp

+29-9
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ void LoRaClass::setFrequency(long frequency)
373373
writeRegister(REG_FRF_LSB, (uint8_t)(frf >> 0));
374374
}
375375

376+
int LoRaClass::getSpreadingFactor()
377+
{
378+
return readRegister(REG_MODEM_CONFIG_2) >> 4;
379+
}
380+
376381
void LoRaClass::setSpreadingFactor(int sf)
377382
{
378383
if (sf < 6) {
@@ -390,22 +395,23 @@ void LoRaClass::setSpreadingFactor(int sf)
390395
}
391396

392397
writeRegister(REG_MODEM_CONFIG_2, (readRegister(REG_MODEM_CONFIG_2) & 0x0f) | ((sf << 4) & 0xf0));
398+
setLdoFlag();
393399
}
394400

395401
long LoRaClass::getSignalBandwidth()
396402
{
397403
byte bw = (readRegister(REG_MODEM_CONFIG_1) >> 4);
398404
switch (bw) {
399405
case 0: return 7.8E3;
400-
case 1: return 10.4E3;
401-
case 2: return 15.6E3;
402-
case 3: return 20.8E3;
403-
case 4: return 31.25E3;
404-
case 5: return 41.7E3;
405-
case 6: return 62.5E3;
406-
case 7: return 125E3;
407-
case 8: return 250E3;
408-
case 9: return 500E3;
406+
case 1: return 10.4E3;
407+
case 2: return 15.6E3;
408+
case 3: return 20.8E3;
409+
case 4: return 31.25E3;
410+
case 5: return 41.7E3;
411+
case 6: return 62.5E3;
412+
case 7: return 125E3;
413+
case 8: return 250E3;
414+
case 9: return 500E3;
409415
}
410416
}
411417

@@ -436,6 +442,20 @@ void LoRaClass::setSignalBandwidth(long sbw)
436442
}
437443

438444
writeRegister(REG_MODEM_CONFIG_1, (readRegister(REG_MODEM_CONFIG_1) & 0x0f) | (bw << 4));
445+
setLdoFlag();
446+
}
447+
448+
void LoRaClass::setLdoFlag()
449+
{
450+
// Section 4.1.1.5
451+
long symbolDuration = 1000 / ( getSignalBandwidth() / (1L << getSpreadingFactor()) ) ;
452+
453+
// Section 4.1.1.6
454+
boolean ldoOn = symbolDuration > 16;
455+
456+
uint8_t config3 = readRegister(REG_MODEM_CONFIG_3);
457+
bitWrite(config3, 3, ldoOn);
458+
writeRegister(REG_MODEM_CONFIG_3, config3);
439459
}
440460

441461
void LoRaClass::setCodingRate4(int denominator)

src/LoRa.h

+3
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ class LoRaClass : public Stream {
7272

7373
void handleDio0Rise();
7474

75+
int getSpreadingFactor();
7576
long getSignalBandwidth();
7677

78+
void setLdoFlag();
79+
7780
uint8_t readRegister(uint8_t address);
7881
void writeRegister(uint8_t address, uint8_t value);
7982
uint8_t singleTransfer(uint8_t address, uint8_t value);

0 commit comments

Comments
 (0)