Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: DISCO-L072CZ-LRWAN1_LoRa_PingPong
Fork of SX1276GenericLib by
Revision 55:00c1f5b83920, committed 2017-05-19
- Comitter:
- Helmut Tschemernjak
- Date:
- Fri May 19 15:55:19 2017 +0200
- Parent:
- 54:0d8ea87fbab9
- Child:
- 56:4fddac05ac07
- Commit message:
- Added LoRa bandwidth mapping table, now the SetRx/Tx frequency is in Hz.
Changed in this revision
--- a/LoRa_TODO.txt Fri May 19 11:50:12 2017 +0200 +++ b/LoRa_TODO.txt Fri May 19 15:55:19 2017 +0200 @@ -36,5 +36,7 @@ - Use also void pointer for FiFo Write/Read and regular SPI Read/Write - Added return value to Init, we check for a radio availability (May 2017 Helmut) - Added a RxSignalPending which verifies if we have a signal pending in receive state. (May 2017 Helmut) +- Added LoRa bandwidth mapping table, now the SetRx/Tx frequency is in Hz. (May 2017 Helmut) +
--- a/sx1276/sx1276.cpp Fri May 19 11:50:12 2017 +0200
+++ b/sx1276/sx1276.cpp Fri May 19 15:55:19 2017 +0200
@@ -23,7 +23,7 @@
-const FskBandwidth_t SX1276::FskBandwidths[] =
+const SX1276::BandwidthMap SX1276::FskBandwidths[] =
{
{ 2600 , 0x17 },
{ 3100 , 0x0F },
@@ -49,6 +49,21 @@
{ 300000, 0x00 }, // Invalid Bandwidth
};
+const SX1276::BandwidthMap SX1276::LoRaBandwidths[] =
+{
+ { 7800, 0 }, // 7.8 kHz requires TCXO
+ { 10400, 1 }, // 10.4 kHz requires TCXO
+ { 15600, 2 }, // 15.6 kHz requires TCXO
+ { 20800, 3 }, // 20.8 kHz requires TCXO
+ { 31200, 4 }, // 31.2 kHz requires TCXO
+ { 41400, 5 }, // 41.4 kHz requires TCXO
+ { 62500, 6 }, // 62.5 kHz requires TCXO
+ { 125000, 7 }, // the LoRa protocol default
+ { 250000, 8 },
+ { 250000, 9 },
+ { 0 , 10 }, // Invalid Bandwidth, reserved
+ };
+
/*!
@@ -57,7 +72,7 @@
* @remark Can be automatically generated by the SX1276 GUI (not yet implemented)
*/
-const RadioRegisters_t SX1276::RadioRegsInit[] = {
+const SX1276::RadioRegisters SX1276::RadioRegsInit[] = {
{ MODEM_FSK , REG_LNA , 0x23 },
{ MODEM_FSK , REG_RXCONFIG , 0x1E },
{ MODEM_FSK , REG_RSSICONFIG , 0xD2 },
@@ -116,7 +131,7 @@
void SX1276::RadioRegistersInit( )
{
uint8_t i = 0;
- for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ )
+ for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters ); i++ )
{
SetModem( RadioRegsInit[i].Modem );
Write( RadioRegsInit[i].Addr, RadioRegsInit[i].Value );
@@ -246,7 +261,7 @@
{
uint8_t i;
- for( i = 0; i < ( sizeof( FskBandwidths ) / sizeof( FskBandwidth_t ) ) - 1; i++ )
+ for( i = 0; i < ( sizeof( FskBandwidths ) / sizeof( BandwidthMap ) ) - 1; i++ )
{
if( ( bandwidth >= FskBandwidths[i].bandwidth ) && ( bandwidth < FskBandwidths[i + 1].bandwidth ) )
{
@@ -257,6 +272,27 @@
while( 1 );
}
+/*!
+ * Returns the known LoRa bandwidth registers value
+ *
+ * \param [IN] bandwidth Bandwidth value in Hz
+ * \retval regValue Bandwidth register value.
+ */
+uint8_t SX1276::GetLoRaBandwidthRegValue( uint32_t bandwidth )
+{
+ uint8_t i;
+
+ for( i = 0; i < ( sizeof( LoRaBandwidths ) / sizeof( BandwidthMap ) ) - 1; i++ )
+ {
+ if( ( bandwidth >= LoRaBandwidths[i].bandwidth ) && ( bandwidth < LoRaBandwidths[i + 1].bandwidth ) )
+ {
+ return LoRaBandwidths[i].RegValue;
+ }
+ }
+ // ERROR: Value not found
+ while( 1 );
+}
+
void SX1276::SetRxConfig( RadioModems_t modem, uint32_t bandwidth,
uint32_t datarate, uint8_t coderate,
uint32_t bandwidthAfc, uint16_t preambleLen,
@@ -313,6 +349,7 @@
break;
case MODEM_LORA:
{
+ bandwidth = GetLoRaBandwidthRegValue(bandwidth);
if( bandwidth > LORA_BANKWIDTH_500kHz )
{
// Fatal error: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
@@ -473,6 +510,7 @@
case MODEM_LORA:
{
this->settings.LoRa.Power = power;
+ bandwidth = GetLoRaBandwidthRegValue(bandwidth);
if( bandwidth > LORA_BANKWIDTH_500kHz )
{
// Fatal error: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
--- a/sx1276/sx1276.h Fri May 19 11:50:12 2017 +0200
+++ b/sx1276/sx1276.h Fri May 19 15:55:19 2017 +0200
@@ -62,26 +62,6 @@
-/*!
- * FSK bandwidth definition
- */
-typedef struct
-{
- uint32_t bandwidth;
- uint8_t RegValue;
-}FskBandwidth_t;
-
-
-/*!
- * Radio registers definition
- */
-typedef struct
-{
- ModemType Modem;
- uint8_t Addr;
- uint8_t Value;
-}RadioRegisters_t;
-
/*!
* Type of the supported board. [SX1276MB1MAS / SX1276MB1LAS]
@@ -96,24 +76,6 @@
}BoardType_t;
-
-typedef enum {
- LORA_BANKWIDTH_7kHz = 0, // 7.8 kHz requires TCXO
- LORA_BANKWIDTH_10kHz = 1, // 10.4 kHz requires TCXO
- LORA_BANKWIDTH_15kHz = 2, // 15.6 kHz requires TCXO
- LORA_BANKWIDTH_20kHz = 3, // 20.8 kHz requires TCXO
- LORA_BANKWIDTH_31kHz = 4, // 31.2 kHz requires TCXO
- LORA_BANKWIDTH_41kHz = 5, // 41.4 kHz requires TCXO
- LORA_BANKWIDTH_62kHz = 6, // 62.5 kHz requires TCXO
-
- LORA_BANKWIDTH_125kHz = 7,
- LORA_BANKWIDTH_250kHz = 8,
- LORA_BANKWIDTH_500kHz = 9,
- LORA_BANKWIDTH_RESERVED = 10,
-} Lora_bandwidth_t;
-
-
-
typedef enum {
LORA_SF6 = 6, // 64 chips/symbol, SF6 requires an TCXO!
LORA_SF7 = 7, // 128 chips/symbol
@@ -175,7 +137,15 @@
RadioSettings_t settings;
- static const FskBandwidth_t FskBandwidths[];
+ /*!
+ * FSK bandwidth definition
+ */
+ struct BandwidthMap {
+ uint32_t bandwidth;
+ uint8_t RegValue;
+ };
+ static const struct BandwidthMap FskBandwidths[];
+ static const struct BandwidthMap LoRaBandwidths[];
protected:
@@ -190,6 +160,9 @@
SX1276( RadioEvents_t *events);
virtual ~SX1276( );
+
+
+
//-------------------------------------------------------------------------
// Redefined Radio functions
//-------------------------------------------------------------------------
@@ -493,8 +466,17 @@
//-------------------------------------------------------------------------
// Board relative functions
//-------------------------------------------------------------------------
-
- static const RadioRegisters_t RadioRegsInit[];
+ /*!
+ * Radio registers definition
+ */
+ struct RadioRegisters {
+ ModemType Modem;
+ uint8_t Addr;
+ uint8_t Value;
+ };
+
+
+ static const struct RadioRegisters RadioRegsInit[];
typedef enum {
RXTimeoutTimer,
@@ -634,6 +616,22 @@
* \retval regValue Bandwidth register value.
*/
static uint8_t GetFskBandwidthRegValue( uint32_t bandwidth );
+
+ static uint8_t GetLoRaBandwidthRegValue( uint32_t bandwidth );
+
+ enum {
+ LORA_BANKWIDTH_7kHz = 0, // 7.8 kHz requires TCXO
+ LORA_BANKWIDTH_10kHz = 1, // 10.4 kHz requires TCXO
+ LORA_BANKWIDTH_15kHz = 2, // 15.6 kHz requires TCXO
+ LORA_BANKWIDTH_20kHz = 3, // 20.8 kHz requires TCXO
+ LORA_BANKWIDTH_31kHz = 4, // 31.2 kHz requires TCXO
+ LORA_BANKWIDTH_41kHz = 5, // 41.4 kHz requires TCXO
+ LORA_BANKWIDTH_62kHz = 6, // 62.5 kHz requires TCXO
+ LORA_BANKWIDTH_125kHz = 7,
+ LORA_BANKWIDTH_250kHz = 8,
+ LORA_BANKWIDTH_500kHz = 9,
+ LORA_BANKWIDTH_RESERVED = 10,
+ };
};
#endif // __SX1276_H__
