Basic LoRa receiver example

Dependencies:   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 LR1110, then import LR1110 driver into your program.
If you're using NAmote72 or Murata discovery, then you must import only sx127x driver.
If you're using Type1SJ select target DISCO_L072CZ_LRWAN1 and import sx126x driver into your program.

On default serial port, this project will print out (at 9600bps) reset-rx once at startup.

Use project simple_tx on transmtting end.

Committer:
Wayne Roberts
Date:
Fri Jun 12 11:44:32 2020 -0700
Revision:
4:db424a8eb3c6
Parent:
2:5e56875de51b
use latest radio-HAL

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wayne Roberts 0:7c7b86c38e6f 1 #include "radio.h"
Wayne Roberts 0:7c7b86c38e6f 2
Wayne Roberts 4:db424a8eb3c6 3 #if defined(SX128x_H)
Wayne Roberts 4:db424a8eb3c6 4 #define BW_KHZ 200
Wayne Roberts 4:db424a8eb3c6 5 #define SPREADING_FACTOR 7
Wayne Roberts 4:db424a8eb3c6 6 #define CF_HZ 2487000000
Wayne Roberts 4:db424a8eb3c6 7 #define TX_DBM 6
Wayne Roberts 4:db424a8eb3c6 8 #else
Wayne Roberts 4:db424a8eb3c6 9 #if defined(SX128x_H)
Wayne Roberts 4:db424a8eb3c6 10 #define TX_DBM (Radio::chipType == CHIP_TYPE_SX1262 ? 20 : 14)
Wayne Roberts 4:db424a8eb3c6 11 #else
Wayne Roberts 4:db424a8eb3c6 12 #define TX_DBM 20
Wayne Roberts 4:db424a8eb3c6 13 #endif
Wayne Roberts 0:7c7b86c38e6f 14 #define BW_KHZ 125
Wayne Roberts 0:7c7b86c38e6f 15 #define SPREADING_FACTOR 7
Wayne Roberts 0:7c7b86c38e6f 16 #define CF_HZ 915000000
Wayne Roberts 0:7c7b86c38e6f 17 #endif
Wayne Roberts 0:7c7b86c38e6f 18
Wayne Roberts 0:7c7b86c38e6f 19 DigitalOut myled(LED1);
Wayne Roberts 0:7c7b86c38e6f 20
Wayne Roberts 0:7c7b86c38e6f 21 /**********************************************************************/
Wayne Roberts 0:7c7b86c38e6f 22
Wayne Roberts 0:7c7b86c38e6f 23 void txDoneCB()
Wayne Roberts 0:7c7b86c38e6f 24 {
Wayne Roberts 0:7c7b86c38e6f 25 }
Wayne Roberts 0:7c7b86c38e6f 26
Wayne Roberts 0:7c7b86c38e6f 27 void rxDoneCB(uint8_t size, float rssi, float snr)
Wayne Roberts 0:7c7b86c38e6f 28 {
Wayne Roberts 0:7c7b86c38e6f 29 unsigned i;
Wayne Roberts 0:7c7b86c38e6f 30 printf("%.1fdBm snr:%.1fdB\t", rssi, snr);
Wayne Roberts 0:7c7b86c38e6f 31
Wayne Roberts 0:7c7b86c38e6f 32 myled.write(!myled.read()); // toggle LED
Wayne Roberts 0:7c7b86c38e6f 33
Wayne Roberts 0:7c7b86c38e6f 34 for (i = 0; i < size; i++) {
Wayne Roberts 0:7c7b86c38e6f 35 printf("%02x ", Radio::radio.rx_buf[i]);
Wayne Roberts 0:7c7b86c38e6f 36 }
Wayne Roberts 0:7c7b86c38e6f 37 printf("\r\n");
Wayne Roberts 0:7c7b86c38e6f 38 }
Wayne Roberts 0:7c7b86c38e6f 39
Wayne Roberts 0:7c7b86c38e6f 40 const RadioEvents_t rev = {
Wayne Roberts 0:7c7b86c38e6f 41 /* Dio0_top_half */ NULL,
Wayne Roberts 0:7c7b86c38e6f 42 /* TxDone_topHalf */ NULL,
Wayne Roberts 0:7c7b86c38e6f 43 /* TxDone_botHalf */ txDoneCB,
Wayne Roberts 0:7c7b86c38e6f 44 /* TxTimeout */ NULL,
Wayne Roberts 0:7c7b86c38e6f 45 /* RxDone */ rxDoneCB,
Wayne Roberts 0:7c7b86c38e6f 46 /* RxTimeout */ NULL,
Wayne Roberts 0:7c7b86c38e6f 47 /* RxError */ NULL,
Wayne Roberts 0:7c7b86c38e6f 48 /* FhssChangeChannel */NULL,
Wayne Roberts 0:7c7b86c38e6f 49 /* CadDone */ NULL
Wayne Roberts 0:7c7b86c38e6f 50 };
Wayne Roberts 0:7c7b86c38e6f 51
Wayne Roberts 0:7c7b86c38e6f 52 int main()
Wayne Roberts 0:7c7b86c38e6f 53 {
Wayne Roberts 0:7c7b86c38e6f 54 printf("\r\nreset-rx\r\n");
Wayne Roberts 0:7c7b86c38e6f 55
Wayne Roberts 0:7c7b86c38e6f 56 Radio::Init(&rev);
Wayne Roberts 0:7c7b86c38e6f 57
Wayne Roberts 0:7c7b86c38e6f 58 Radio::Standby();
Wayne Roberts 0:7c7b86c38e6f 59 Radio::LoRaModemConfig(BW_KHZ, SPREADING_FACTOR, 1);
Wayne Roberts 0:7c7b86c38e6f 60 Radio::SetChannel(CF_HZ);
Wayne Roberts 0:7c7b86c38e6f 61
Wayne Roberts 0:7c7b86c38e6f 62 // preambleLen, fixLen, crcOn, invIQ
Wayne Roberts 0:7c7b86c38e6f 63 Radio::LoRaPacketConfig(8, false, true, false);
Wayne Roberts 0:7c7b86c38e6f 64
Wayne Roberts 0:7c7b86c38e6f 65 Radio::Rx(0);
Wayne Roberts 0:7c7b86c38e6f 66
Wayne Roberts 0:7c7b86c38e6f 67 for (;;) {
Wayne Roberts 0:7c7b86c38e6f 68 Radio::service();
Wayne Roberts 0:7c7b86c38e6f 69 }
Wayne Roberts 0:7c7b86c38e6f 70 }
Wayne Roberts 0:7c7b86c38e6f 71