basic LoRa transmitter 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.

Use project simple_rx on receiving end.

Committer:
Wayne Roberts
Date:
Fri Feb 12 14:49:02 2021 -0800
Revision:
5:8f8e5a7aab7a
Parent:
4:938655f1726c
remove lr1110, user adds their own radio chip

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wayne Roberts 0:83bfd3e3c4c4 1 #include "radio.h"
Wayne Roberts 0:83bfd3e3c4c4 2
Wayne Roberts 4:938655f1726c 3 #if defined(SX128x_H)
Wayne Roberts 0:83bfd3e3c4c4 4 #define BW_KHZ 200
Wayne Roberts 0:83bfd3e3c4c4 5 #define SPREADING_FACTOR 7
Wayne Roberts 0:83bfd3e3c4c4 6 #define CF_HZ 2487000000
Wayne Roberts 0:83bfd3e3c4c4 7 #define TX_DBM 6
Wayne Roberts 4:938655f1726c 8 #else
Wayne Roberts 4:938655f1726c 9 #if defined(SX126x_H)
Wayne Roberts 4:938655f1726c 10 #define TX_DBM (Radio::chipType == CHIP_TYPE_SX1262 ? 20 : 14)
Wayne Roberts 4:938655f1726c 11 #else
Wayne Roberts 4:938655f1726c 12 #define TX_DBM 20
Wayne Roberts 4:938655f1726c 13 #endif
Wayne Roberts 4:938655f1726c 14 #define BW_KHZ 125
Wayne Roberts 4:938655f1726c 15 #define SPREADING_FACTOR 7
Wayne Roberts 4:938655f1726c 16 #define CF_HZ 915000000
Wayne Roberts 0:83bfd3e3c4c4 17 #endif
Wayne Roberts 0:83bfd3e3c4c4 18
Wayne Roberts 0:83bfd3e3c4c4 19 /**********************************************************************/
Wayne Roberts 2:3f4dfcc3bab6 20 EventQueue queue(4 * EVENTS_EVENT_SIZE);
Wayne Roberts 2:3f4dfcc3bab6 21
Wayne Roberts 2:3f4dfcc3bab6 22 void tx_test()
Wayne Roberts 2:3f4dfcc3bab6 23 {
Wayne Roberts 4:938655f1726c 24 static uint8_t seq = 0;
Wayne Roberts 2:3f4dfcc3bab6 25
Wayne Roberts 2:3f4dfcc3bab6 26 Radio::radio.tx_buf[0] = seq++; /* set payload */
Wayne Roberts 2:3f4dfcc3bab6 27 Radio::Send(1, 0, 0, 0); /* begin transmission */
Wayne Roberts 2:3f4dfcc3bab6 28 printf("sent\r\n");
Wayne Roberts 2:3f4dfcc3bab6 29
Wayne Roberts 2:3f4dfcc3bab6 30 /* {
Wayne Roberts 2:3f4dfcc3bab6 31 mbed_stats_cpu_t stats;
Wayne Roberts 2:3f4dfcc3bab6 32 mbed_stats_cpu_get(&stats);
Wayne Roberts 2:3f4dfcc3bab6 33 printf("canDeep:%u ", sleep_manager_can_deep_sleep());
Wayne Roberts 2:3f4dfcc3bab6 34 printf("Uptime: %llu ", stats.uptime / 1000);
Wayne Roberts 2:3f4dfcc3bab6 35 printf("Sleep time: %llu ", stats.sleep_time / 1000);
Wayne Roberts 2:3f4dfcc3bab6 36 printf("Deep Sleep: %llu\r\n", stats.deep_sleep_time / 1000);
Wayne Roberts 2:3f4dfcc3bab6 37 }*/
Wayne Roberts 2:3f4dfcc3bab6 38 }
Wayne Roberts 0:83bfd3e3c4c4 39
Wayne Roberts 0:83bfd3e3c4c4 40 void txDoneCB()
Wayne Roberts 0:83bfd3e3c4c4 41 {
Wayne Roberts 2:3f4dfcc3bab6 42 printf("got-tx-done\r\n");
Wayne Roberts 2:3f4dfcc3bab6 43 queue.call_in(500, tx_test);
Wayne Roberts 0:83bfd3e3c4c4 44 }
Wayne Roberts 0:83bfd3e3c4c4 45
Wayne Roberts 0:83bfd3e3c4c4 46 void rxDoneCB(uint8_t size, float rssi, float snr)
Wayne Roberts 0:83bfd3e3c4c4 47 {
Wayne Roberts 0:83bfd3e3c4c4 48 }
Wayne Roberts 0:83bfd3e3c4c4 49
Wayne Roberts 2:3f4dfcc3bab6 50
Wayne Roberts 2:3f4dfcc3bab6 51 void radio_irq_callback()
Wayne Roberts 2:3f4dfcc3bab6 52 {
Wayne Roberts 2:3f4dfcc3bab6 53 queue.call(Radio::service);
Wayne Roberts 2:3f4dfcc3bab6 54 }
Wayne Roberts 2:3f4dfcc3bab6 55
Wayne Roberts 2:3f4dfcc3bab6 56
Wayne Roberts 0:83bfd3e3c4c4 57 const RadioEvents_t rev = {
Wayne Roberts 4:938655f1726c 58 /* DioPin_top_half */ radio_irq_callback,
Wayne Roberts 0:83bfd3e3c4c4 59 /* TxDone_topHalf */ NULL,
Wayne Roberts 0:83bfd3e3c4c4 60 /* TxDone_botHalf */ txDoneCB,
Wayne Roberts 0:83bfd3e3c4c4 61 /* TxTimeout */ NULL,
Wayne Roberts 0:83bfd3e3c4c4 62 /* RxDone */ rxDoneCB,
Wayne Roberts 0:83bfd3e3c4c4 63 /* RxTimeout */ NULL,
Wayne Roberts 0:83bfd3e3c4c4 64 /* RxError */ NULL,
Wayne Roberts 0:83bfd3e3c4c4 65 /* FhssChangeChannel */NULL,
Wayne Roberts 0:83bfd3e3c4c4 66 /* CadDone */ NULL
Wayne Roberts 0:83bfd3e3c4c4 67 };
Wayne Roberts 0:83bfd3e3c4c4 68
Wayne Roberts 0:83bfd3e3c4c4 69 int main()
Wayne Roberts 0:83bfd3e3c4c4 70 {
Wayne Roberts 0:83bfd3e3c4c4 71 printf("\r\nreset-tx ");
Wayne Roberts 0:83bfd3e3c4c4 72
Wayne Roberts 0:83bfd3e3c4c4 73 Radio::Init(&rev);
Wayne Roberts 0:83bfd3e3c4c4 74
Wayne Roberts 0:83bfd3e3c4c4 75 Radio::Standby();
Wayne Roberts 0:83bfd3e3c4c4 76 Radio::LoRaModemConfig(BW_KHZ, SPREADING_FACTOR, 1);
Wayne Roberts 0:83bfd3e3c4c4 77 Radio::SetChannel(CF_HZ);
Wayne Roberts 0:83bfd3e3c4c4 78
Wayne Roberts 0:83bfd3e3c4c4 79 Radio::set_tx_dbm(TX_DBM);
Wayne Roberts 0:83bfd3e3c4c4 80
Wayne Roberts 0:83bfd3e3c4c4 81 // preambleLen, fixLen, crcOn, invIQ
Wayne Roberts 0:83bfd3e3c4c4 82 Radio::LoRaPacketConfig(8, false, true, false);
Wayne Roberts 0:83bfd3e3c4c4 83
Wayne Roberts 2:3f4dfcc3bab6 84 queue.call_in(500, tx_test);
Wayne Roberts 0:83bfd3e3c4c4 85
Wayne Roberts 2:3f4dfcc3bab6 86 queue.dispatch();
Wayne Roberts 0:83bfd3e3c4c4 87 }
Wayne Roberts 0:83bfd3e3c4c4 88