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:
Wed Sep 05 17:36:22 2018 -0700
Revision:
2:5e56875de51b
Parent:
0:7c7b86c38e6f
Child:
4:db424a8eb3c6
reset radio chip at start

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