Driver library for SX1272/SX1276 transceivers

Dependents:   LORA_RX LORA_TX WindConcentrator hid_test ... more

/media/uploads/dudmuck/lora.png

Driver library for SX1272 and SX1276 radio transceivers.

This device uses CSS modulation to provide much improved link budget. The RF hardware is same as in FSK devices, just with added LoRa spread-spectrum modem.

This library provides functions to configure radio chip and transmit & receive packets.

Using This Library

Library function service_radio() must be called continuously from main loop, to service interrupts from radio.

/media/uploads/dudmuck/sx1272rf1_connector_300.jpg

Board Specific implementation

FunctionPointer for rf_switch callback allows the program to implement control of RF switch unique to their board. Example options are:

  • SKY13373 for external power amplifier implementation. Requires two DigitalOut pins.
  • SKY13350 using PA_BOOST. requires two DigitalOut pins.
  • PE4259-63: controlled directly by radio chip, no software function needed. However, in the case of SX1276MB1xAS, the RXTX pin on IO2 should be driven by this callback function when R16 is installed (without R15) on this shield board.

Some configurations may need to force the use of RFO or PA_BOOST, or a board could offer both options. The rf_switch function pointer callback should support the implementation choice on the board.

further reading

Revision:
4:d987ac2836bf
Parent:
2:fdae76e1215e
Child:
6:5d94ee847016
Child:
7:927a05f84ede
--- a/sx127x.cpp	Fri May 02 01:18:59 2014 +0000
+++ b/sx127x.cpp	Fri May 02 23:35:30 2014 +0000
@@ -42,22 +42,20 @@
     RegDioMapping1.octet = read_reg(REG_DIOMAPPING1);
     RegDioMapping2.octet = read_reg(REG_DIOMAPPING2);
     
-    if (!RegOpMode.bits.LongRangeMode) {
+/*    if (!RegOpMode.bits.LongRangeMode) {
         if (RegOpMode.bits.Mode != RF_OPMODE_SLEEP)
             set_opmode(RF_OPMODE_SLEEP);
         RegOpMode.bits.LongRangeMode = 1;
         write_reg(REG_OPMODE, RegOpMode.octet);
-    }
-    
-
+    }*/
     
     get_type();
     
-    // turn on PA BOOST, eval boards are wired for this connection
-    RegPaConfig.bits.PaSelect = 1;
-    write_reg(REG_PACONFIG, RegPaConfig.octet);
-    
-
+    if (type == SX1272) {
+        // turn on PA BOOST, eval boards are wired for this connection
+        RegPaConfig.bits.PaSelect = 1;
+        write_reg(REG_PACONFIG, RegPaConfig.octet);
+    }
 }
 
 void SX127x::get_type()
@@ -148,7 +146,18 @@
     return ret;
 }
 
-void SX127x::write_reg_u24(uint8_t addr, uint32_t data)
+void SX127x::write_u16(uint8_t addr, uint16_t data)
+{
+    m_cs = 0;   // Select the device by seting chip select low
+
+    m_spi.write(addr | 0x80); // bit7 is high for writing to radio
+    m_spi.write((data >> 8) & 0xff);
+    m_spi.write(data & 0xff);
+ 
+    m_cs = 1;   // Deselect the device
+}
+
+void SX127x::write_u24(uint8_t addr, uint32_t data)
 {
     m_cs = 0;   // Select the device by seting chip select low
 
@@ -203,7 +212,7 @@
     uint32_t frf;
     
     frf = MHz / FREQ_STEP_MHZ;
-    write_reg_u24(REG_FRFMSB, frf);
+    write_u24(REG_FRFMSB, frf);
     
     if (MHz < 525)
         HF = false;