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:
3:3bf2515b1eed
Child:
8:c9592cbc9f86
--- a/sx127x_fsk.cpp	Fri May 02 01:18:59 2014 +0000
+++ b/sx127x_fsk.cpp	Fri May 02 23:35:30 2014 +0000
@@ -75,6 +75,62 @@
     m_xcvr.set_opmode(RF_OPMODE_STANDBY);     
 }
 
+void SX127x_fsk::init()
+{
+    m_xcvr.set_opmode(RF_OPMODE_STANDBY);
+    
+    RegRxConfig.bits.RxTrigger = 6; // have RX restart (trigger) on preamble detection
+    RegRxConfig.bits.AfcAutoOn = 1; // have AFC performed on RX restart (RX trigger)
+    m_xcvr.write_reg(REG_FSK_RXCONFIG, RegRxConfig.octet);
+    
+    RegPreambleDetect.bits.PreambleDetectorOn = 1;  // enable preamble detector
+    m_xcvr.write_reg(REG_FSK_PREAMBLEDETECT, RegPreambleDetect.octet);
+    
+    m_xcvr.write_reg(REG_FSK_SYNCVALUE1, 0x55);
+    m_xcvr.write_reg(REG_FSK_SYNCVALUE2, 0x6f); 
+    m_xcvr.write_reg(REG_FSK_SYNCVALUE3, 0x4e);
+    RegSyncConfig.bits.SyncSize = 2;
+    m_xcvr.write_reg(REG_FSK_SYNCCONFIG, RegSyncConfig.octet);
+    
+    // in case these were changed from default:
+    set_bitrate(4800);
+    set_tx_fdev_hz(5050);
+    set_rx_dcc_bw_hz(10500, 0);    // rxbw
+    set_rx_dcc_bw_hz(50000, 1);    // afcbw
+}
+    
+uint32_t SX127x_fsk::get_bitrate()
+{
+    uint16_t br = m_xcvr.read_u16(REG_FSK_BITRATEMSB);
+
+    if (br == 0)
+        return 0;
+    else
+        return XTAL_FREQ / br;
+}
+
+void SX127x_fsk::set_bitrate(uint32_t bps)
+{
+    uint16_t tmpBitrate = XTAL_FREQ / bps;
+    //printf("tmpBitrate:%d = %d / %d\r\n", tmpBitrate, XTAL_FREQ, bps);
+    m_xcvr.write_u16(REG_FSK_BITRATEMSB, tmpBitrate);
+}
+
+void SX127x_fsk::set_tx_fdev_hz(uint32_t hz)
+{
+    float tmpFdev = hz / FREQ_STEP_HZ;
+    uint16_t v;
+    //printf("tmpFdev:%f = %d / %f\r\n", tmpFdev, hz, FREQ_STEP_HZ);
+    v = (uint16_t)tmpFdev;
+    m_xcvr.write_u16(REG_FSK_FDEVMSB, v);
+}
+    
+uint32_t SX127x_fsk::get_tx_fdev_hz(void)
+{
+    uint16_t fdev = m_xcvr.read_u16(REG_FSK_FDEVMSB);
+    return fdev * FREQ_STEP_HZ;
+}
+
 uint32_t SX127x_fsk::ComputeRxBw( uint8_t mantisse, uint8_t exponent )
 {
     // rxBw