raises pin at time instructed by received LoRa packet.

Dependencies:   sx126x sx12xx_hal

radio chip selection

Radio chip driver is not included, allowing choice of radio device.
If you're using SX1272 or SX1276, then import sx127x driver into your program.
if you're using SX1261 or SX1262, then import sx126x driver into your program.
if you're using SX1280, then import sx1280 driver into your program.
If you're using NAmote72 or Murata discovery, then you must import only sx127x driver.

Transmitter side is at Alarm Slave project page.
Output is observed on nucleo morpho connector pins pin[A-D]: see code for actual pins used.

Files at this revision

API Documentation at this revision

Comitter:
Wayne Roberts
Date:
Wed Jul 18 18:50:19 2018 -0700
Parent:
2:bf201940a9db
Commit message:
use sx12xx_hal

Changed in this revision

SX127x.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
sx126x.lib Show annotated file Show diff for this revision Revisions of this file
sx12xx_hal.lib Show annotated file Show diff for this revision Revisions of this file
diff -r bf201940a9db -r f81d64ff0164 SX127x.lib
--- a/SX127x.lib	Fri Jan 26 01:19:39 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://developer.mbed.org/users/dudmuck/code/SX127x/#b66d7a057b22
diff -r bf201940a9db -r f81d64ff0164 main.cpp
--- a/main.cpp	Fri Jan 26 01:19:39 2018 +0000
+++ b/main.cpp	Wed Jul 18 18:50:19 2018 -0700
@@ -1,69 +1,29 @@
-#include "sx127x_lora.h"
+#include "radio.h"
  
 DigitalOut myled(LED1);
-#ifdef TARGET_DISCO_L072CZ_LRWAN1
 
-    SPI spi(PA_7, PA_6, PB_3); // mosi, miso, sclk
-    //           dio0, dio1,  nss,  spi,  rst
-    SX127x radio(PB_4, PB_1, PA_15, spi, PC_0);
-    
-    #define CRF1    PA_1
-    #define CRF2    PC_2
-    #define CRF3    PC_1
-    DigitalOut Vctl1(CRF1);
-    DigitalOut Vctl2(CRF2);
-    DigitalOut Vctl3(CRF3);    
-    
-    void rfsw_callback()
-    {
-        if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) {
-            Vctl1 = 0;        
-            if (radio.RegPaConfig.bits.PaSelect) {
-                Vctl2 = 0;
-                Vctl3 = 1;                        
-            } else {
-                Vctl2 = 1;
-                Vctl3 = 0;            
-            }
-        } else {
-            if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE)
-                Vctl1 = 1;
-            else
-                Vctl1 = 0;
-            
-            Vctl2 = 0;
-            Vctl3 = 0;        
-        }
-    }    
-    
+#if defined(SX127x_H) || defined(SX126x_H)
+    #define BW_KHZ              500
+    #define SPREADING_FACTOR    11
+    #define CF_HZ               910800000
+#elif defined(SX128x_H)
+    #define BW_KHZ              200
+    #define SPREADING_FACTOR    11
+    #define CF_HZ               2487000000
+#endif
+
+#ifdef TARGET_DISCO_L072CZ_LRWAN1
     DigitalOut pinA(PB_12);
     DigitalOut pinB(PB_13);
     DigitalOut pinC(PB_14);
     DigitalOut pinD(PB_15);
 #else
-    SPI spi(D11, D12, D13); // mosi, miso, sclk
-    //           dio0, dio1, nss, spi, rst
-    SX127x radio(  D2,   D3, D10, spi, A0); // sx1276 arduino shield
-    
-    DigitalInOut rfsw(A4);    // for SX1276 arduino shield
-     
-    void rfsw_callback()
-    {
-        if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER)
-            rfsw = 1;
-        else
-            rfsw = 0;
-    }
-    
     DigitalOut pinA(PC_3);
     DigitalOut pinB(PC_2);
     DigitalOut pinC(PC_6);
     DigitalOut pinD(PC_8);
 #endif /* !TARGET_DISCO_L072CZ_LRWAN1 */
 
-/**********************************************************************/
-SX127x_lora lora(radio);
-
 DigitalOut* pin; 
 Timeout to;
 
@@ -74,6 +34,8 @@
 #define CMD_PINC       0x06
 #define CMD_PIND       0x08
 
+/**********************************************************************/
+
 void alarm_pin_clr()
 {
     pin->write(0);
@@ -111,23 +73,22 @@
 
 void get_alarm()
 {
-    uint16_t rx_crc, crc = crc_ccitt(radio.rx_buf, 5);
-    rx_crc = radio.rx_buf[5];
+    uint16_t rx_crc, crc = crc_ccitt(Radio::radio.rx_buf, 5);
+    rx_crc = Radio::radio.rx_buf[5];
     rx_crc <<= 8;
-    rx_crc += radio.rx_buf[6];
+    rx_crc += Radio::radio.rx_buf[6];
     //printf("%u) crc rx:%04x, calc:%04x\r\n", lora.RegRxNbBytes, rx_crc, crc);
     if (crc == rx_crc) {
-        uint8_t c = radio.rx_buf[0];
-        //if (radio.rx_buf[0] == CMD_ALARM)
+        uint8_t c = Radio::radio.rx_buf[0];
         if (c == CMD_PINA || c == CMD_PINB || c == CMD_PINC || c == CMD_PIND) {
             unsigned delay;
-            delay = radio.rx_buf[1];
+            delay = Radio::radio.rx_buf[1];
             delay <<= 8;
-            delay += radio.rx_buf[2];
+            delay += Radio::radio.rx_buf[2];
             delay <<= 8;
-            delay += radio.rx_buf[3];
+            delay += Radio::radio.rx_buf[3];
             delay <<= 8;
-            delay += radio.rx_buf[4];
+            delay += Radio::radio.rx_buf[4];
             switch (c) {
                 case CMD_PINA: pin = &pinA; break;
                 case CMD_PINB: pin = &pinB; break;
@@ -137,55 +98,49 @@
             to.attach_us(&alarm_pin_set, delay);
             printf("delay:%u\r\n", delay);
         } else
-            printf("cmd? %02x\r\n", radio.rx_buf[0]);
+            printf("cmd? %02x\r\n", Radio::radio.rx_buf[0]);
     } else
         printf("crc fail %04x, %04x\r\n", rx_crc, crc);
 }
+
+void txDoneCB()
+{
+}
+
+void rxDoneCB(uint8_t size, float Rssi, float Snr)
+{
+    get_alarm();
+    printf("%.1fdBm  snr:%.1fdB ", Rssi, Snr);
+}
+
+const RadioEvents_t rev = {
+    /* Dio0_top_half */     NULL,
+    /* TxDone_topHalf */    NULL,
+    /* TxDone_botHalf */    txDoneCB,
+    /* TxTimeout  */        NULL,
+    /* RxDone  */           rxDoneCB,
+    /* RxTimeout  */        NULL,
+    /* RxError  */          NULL,
+    /* FhssChangeChannel  */NULL,
+    /* CadDone  */          NULL
+};
+
  
 int main()
 {   
     printf("\r\nreset-rx\r\n");
-    radio.rf_switch = rfsw_callback;
-    
-    radio.set_frf_MHz(910.8);
-    lora.enable();
-    lora.setBw_KHz(500);
-    lora.setSf(11);
+
+
+    Radio::Init(&rev);
+
+    Radio::Standby();
+    Radio::LoRaModemConfig(BW_KHZ, SPREADING_FACTOR, 1);
+    Radio::LoRaPacketConfig(8, false, true, false);  // preambleLen, fixLen, crcOn, invIQ
+    Radio::SetChannel(CF_HZ);
     
-    radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);    
-#ifdef TARGET_DISCO_L072CZ_LRWAN1
-    radio.RegPaConfig.bits.PaSelect = 1;
-#else
-    /* RFO or PABOOST choice:
-     * SX1276 shield: RFO if using 900MHz, or PA_BOOST if using 433MHz
-     */
-    rfsw.input();
-    if (rfsw.read()) {
-        printf("LAS\r\n");
-        /* LAS HF=PA_BOOST  LF=RFO */
-        if (radio.HF)
-            radio.RegPaConfig.bits.PaSelect = 1;
-        else
-            radio.RegPaConfig.bits.PaSelect = 0;
-    } else {
-        /* MAS shield board, only RFO TX */
-        radio.RegPaConfig.bits.PaSelect = 0;
-        printf("MAS\r\n");
-    }
-    rfsw.output();
-#endif /* !TARGET_DISCO_L072CZ_LRWAN1 */
-    radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
-                
-    lora.start_rx(RF_OPMODE_RECEIVER);
+    Radio::Rx(0);
     
     for (;;) {     
-        if (lora.service() == SERVICE_READ_FIFO) {
-            /*int i;
-            for (i = 0; i < lora.RegRxNbBytes; i++) {
-                printf("%02x ", radio.rx_buf[i]);
-            }
-            printf("\r\n");*/
-            get_alarm();
-        }
+        Radio::service();
     }
 }
diff -r bf201940a9db -r f81d64ff0164 mbed-os.lib
--- a/mbed-os.lib	Fri Jan 26 01:19:39 2018 +0000
+++ b/mbed-os.lib	Wed Jul 18 18:50:19 2018 -0700
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#96d9a00d0a1d25095b330095fa81c40f7741777c
+https://github.com/ARMmbed/mbed-os/#dd6482b9555c43cab2e80c9e3715edf1806f87d9
diff -r bf201940a9db -r f81d64ff0164 sx126x.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sx126x.lib	Wed Jul 18 18:50:19 2018 -0700
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/dudmuck/code/sx126x/#497af0bd9e53
diff -r bf201940a9db -r f81d64ff0164 sx12xx_hal.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sx12xx_hal.lib	Wed Jul 18 18:50:19 2018 -0700
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/dudmuck/code/sx12xx_hal/#c321b5919516