basic LoRa transmitter example
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.
Use project simple_rx on receiving end.
main.cpp@0:83bfd3e3c4c4, 2018-07-17 (annotated)
- Committer:
- Wayne Roberts
- Date:
- Tue Jul 17 16:18:48 2018 -0700
- Revision:
- 0:83bfd3e3c4c4
- Child:
- 2:3f4dfcc3bab6
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wayne Roberts |
0:83bfd3e3c4c4 | 1 | #include "radio.h" |
Wayne Roberts |
0:83bfd3e3c4c4 | 2 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 3 | #if defined(SX127x_H) |
Wayne Roberts |
0:83bfd3e3c4c4 | 4 | #define BW_KHZ 125 |
Wayne Roberts |
0:83bfd3e3c4c4 | 5 | #define SPREADING_FACTOR 7 |
Wayne Roberts |
0:83bfd3e3c4c4 | 6 | #define CF_HZ 915000000 |
Wayne Roberts |
0:83bfd3e3c4c4 | 7 | #define TX_DBM 20 |
Wayne Roberts |
0:83bfd3e3c4c4 | 8 | #elif defined(SX126x_H) |
Wayne Roberts |
0:83bfd3e3c4c4 | 9 | #define BW_KHZ 125 |
Wayne Roberts |
0:83bfd3e3c4c4 | 10 | #define SPREADING_FACTOR 7 |
Wayne Roberts |
0:83bfd3e3c4c4 | 11 | #define CF_HZ 915000000 |
Wayne Roberts |
0:83bfd3e3c4c4 | 12 | #define TX_DBM (Radio::chipType == CHIP_TYPE_SX1262 ? 20 : 14) |
Wayne Roberts |
0:83bfd3e3c4c4 | 13 | #elif defined(SX128x_H) |
Wayne Roberts |
0:83bfd3e3c4c4 | 14 | #define BW_KHZ 200 |
Wayne Roberts |
0:83bfd3e3c4c4 | 15 | #define SPREADING_FACTOR 7 |
Wayne Roberts |
0:83bfd3e3c4c4 | 16 | #define CF_HZ 2487000000 |
Wayne Roberts |
0:83bfd3e3c4c4 | 17 | #define TX_DBM 6 |
Wayne Roberts |
0:83bfd3e3c4c4 | 18 | #endif |
Wayne Roberts |
0:83bfd3e3c4c4 | 19 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 20 | /**********************************************************************/ |
Wayne Roberts |
0:83bfd3e3c4c4 | 21 | volatile bool txDone; |
Wayne Roberts |
0:83bfd3e3c4c4 | 22 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 23 | void txDoneCB() |
Wayne Roberts |
0:83bfd3e3c4c4 | 24 | { |
Wayne Roberts |
0:83bfd3e3c4c4 | 25 | txDone = true; |
Wayne Roberts |
0:83bfd3e3c4c4 | 26 | } |
Wayne Roberts |
0:83bfd3e3c4c4 | 27 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 28 | void rxDoneCB(uint8_t size, float rssi, float snr) |
Wayne Roberts |
0:83bfd3e3c4c4 | 29 | { |
Wayne Roberts |
0:83bfd3e3c4c4 | 30 | } |
Wayne Roberts |
0:83bfd3e3c4c4 | 31 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 32 | const RadioEvents_t rev = { |
Wayne Roberts |
0:83bfd3e3c4c4 | 33 | /* Dio0_top_half */ NULL, |
Wayne Roberts |
0:83bfd3e3c4c4 | 34 | /* TxDone_topHalf */ NULL, |
Wayne Roberts |
0:83bfd3e3c4c4 | 35 | /* TxDone_botHalf */ txDoneCB, |
Wayne Roberts |
0:83bfd3e3c4c4 | 36 | /* TxTimeout */ NULL, |
Wayne Roberts |
0:83bfd3e3c4c4 | 37 | /* RxDone */ rxDoneCB, |
Wayne Roberts |
0:83bfd3e3c4c4 | 38 | /* RxTimeout */ NULL, |
Wayne Roberts |
0:83bfd3e3c4c4 | 39 | /* RxError */ NULL, |
Wayne Roberts |
0:83bfd3e3c4c4 | 40 | /* FhssChangeChannel */NULL, |
Wayne Roberts |
0:83bfd3e3c4c4 | 41 | /* CadDone */ NULL |
Wayne Roberts |
0:83bfd3e3c4c4 | 42 | }; |
Wayne Roberts |
0:83bfd3e3c4c4 | 43 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 44 | int main() |
Wayne Roberts |
0:83bfd3e3c4c4 | 45 | { |
Wayne Roberts |
0:83bfd3e3c4c4 | 46 | uint8_t seq = 0; |
Wayne Roberts |
0:83bfd3e3c4c4 | 47 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 48 | printf("\r\nreset-tx "); |
Wayne Roberts |
0:83bfd3e3c4c4 | 49 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 50 | Radio::Init(&rev); |
Wayne Roberts |
0:83bfd3e3c4c4 | 51 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 52 | Radio::Standby(); |
Wayne Roberts |
0:83bfd3e3c4c4 | 53 | Radio::LoRaModemConfig(BW_KHZ, SPREADING_FACTOR, 1); |
Wayne Roberts |
0:83bfd3e3c4c4 | 54 | Radio::SetChannel(CF_HZ); |
Wayne Roberts |
0:83bfd3e3c4c4 | 55 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 56 | Radio::set_tx_dbm(TX_DBM); |
Wayne Roberts |
0:83bfd3e3c4c4 | 57 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 58 | // preambleLen, fixLen, crcOn, invIQ |
Wayne Roberts |
0:83bfd3e3c4c4 | 59 | Radio::LoRaPacketConfig(8, false, true, false); |
Wayne Roberts |
0:83bfd3e3c4c4 | 60 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 61 | for (;;) { |
Wayne Roberts |
0:83bfd3e3c4c4 | 62 | Radio::radio.tx_buf[0] = seq; /* set payload */ |
Wayne Roberts |
0:83bfd3e3c4c4 | 63 | txDone = false; |
Wayne Roberts |
0:83bfd3e3c4c4 | 64 | Radio::Send(1, 0, 0, 0); /* begin transmission */ |
Wayne Roberts |
0:83bfd3e3c4c4 | 65 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 66 | printf("sent\r\n"); |
Wayne Roberts |
0:83bfd3e3c4c4 | 67 | while (!txDone) { |
Wayne Roberts |
0:83bfd3e3c4c4 | 68 | Radio::service(); |
Wayne Roberts |
0:83bfd3e3c4c4 | 69 | } |
Wayne Roberts |
0:83bfd3e3c4c4 | 70 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 71 | printf("got-tx-done\r\n"); |
Wayne Roberts |
0:83bfd3e3c4c4 | 72 | |
Wayne Roberts |
0:83bfd3e3c4c4 | 73 | wait(0.5); /* throttle sending rate */ |
Wayne Roberts |
0:83bfd3e3c4c4 | 74 | seq++; /* change payload */ |
Wayne Roberts |
0:83bfd3e3c4c4 | 75 | } |
Wayne Roberts |
0:83bfd3e3c4c4 | 76 | } |
Wayne Roberts |
0:83bfd3e3c4c4 | 77 |