mirror of
https://github.com/sandeepmistry/arduino-LoRa.git
synced 2025-04-19 13:02:14 +03:00
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
This commit is contained in:
parent
5d6a7a398a
commit
cd0df701a9
20
src/LoRa.cpp
20
src/LoRa.cpp
@ -373,6 +373,11 @@ void LoRaClass::setFrequency(long frequency)
|
|||||||
writeRegister(REG_FRF_LSB, (uint8_t)(frf >> 0));
|
writeRegister(REG_FRF_LSB, (uint8_t)(frf >> 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LoRaClass::getSpreadingFactor()
|
||||||
|
{
|
||||||
|
return readRegister(REG_MODEM_CONFIG_2) >> 4;
|
||||||
|
}
|
||||||
|
|
||||||
void LoRaClass::setSpreadingFactor(int sf)
|
void LoRaClass::setSpreadingFactor(int sf)
|
||||||
{
|
{
|
||||||
if (sf < 6) {
|
if (sf < 6) {
|
||||||
@ -390,6 +395,7 @@ void LoRaClass::setSpreadingFactor(int sf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
writeRegister(REG_MODEM_CONFIG_2, (readRegister(REG_MODEM_CONFIG_2) & 0x0f) | ((sf << 4) & 0xf0));
|
writeRegister(REG_MODEM_CONFIG_2, (readRegister(REG_MODEM_CONFIG_2) & 0x0f) | ((sf << 4) & 0xf0));
|
||||||
|
setLdoFlag();
|
||||||
}
|
}
|
||||||
|
|
||||||
long LoRaClass::getSignalBandwidth()
|
long LoRaClass::getSignalBandwidth()
|
||||||
@ -436,6 +442,20 @@ void LoRaClass::setSignalBandwidth(long sbw)
|
|||||||
}
|
}
|
||||||
|
|
||||||
writeRegister(REG_MODEM_CONFIG_1, (readRegister(REG_MODEM_CONFIG_1) & 0x0f) | (bw << 4));
|
writeRegister(REG_MODEM_CONFIG_1, (readRegister(REG_MODEM_CONFIG_1) & 0x0f) | (bw << 4));
|
||||||
|
setLdoFlag();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoRaClass::setLdoFlag()
|
||||||
|
{
|
||||||
|
// Section 4.1.1.5
|
||||||
|
long symbolDuration = 1000 / ( getSignalBandwidth() / (1L << getSpreadingFactor()) ) ;
|
||||||
|
|
||||||
|
// Section 4.1.1.6
|
||||||
|
boolean ldoOn = symbolDuration > 16;
|
||||||
|
|
||||||
|
uint8_t config3 = readRegister(REG_MODEM_CONFIG_3);
|
||||||
|
bitWrite(config3, 3, ldoOn);
|
||||||
|
writeRegister(REG_MODEM_CONFIG_3, config3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaClass::setCodingRate4(int denominator)
|
void LoRaClass::setCodingRate4(int denominator)
|
||||||
|
@ -72,8 +72,11 @@ private:
|
|||||||
|
|
||||||
void handleDio0Rise();
|
void handleDio0Rise();
|
||||||
|
|
||||||
|
int getSpreadingFactor();
|
||||||
long getSignalBandwidth();
|
long getSignalBandwidth();
|
||||||
|
|
||||||
|
void setLdoFlag();
|
||||||
|
|
||||||
uint8_t readRegister(uint8_t address);
|
uint8_t readRegister(uint8_t address);
|
||||||
void writeRegister(uint8_t address, uint8_t value);
|
void writeRegister(uint8_t address, uint8_t value);
|
||||||
uint8_t singleTransfer(uint8_t address, uint8_t value);
|
uint8_t singleTransfer(uint8_t address, uint8_t value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user