May 2021 Tests
Dependencies: SX127x sx12xx_hal
main.cpp@1:b277f5a65c1c, 2019-03-21 (annotated)
- Committer:
- LoRaToolbox
- Date:
- Thu Mar 21 10:22:46 2019 +0000
- Revision:
- 1:b277f5a65c1c
- Parent:
- 0:44fb2db84011
- Child:
- 2:546880a768fa
Include updated comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
LoRaToolbox | 0:44fb2db84011 | 1 | #include "radio.h" |
LoRaToolbox | 0:44fb2db84011 | 2 | |
LoRaToolbox | 1:b277f5a65c1c | 3 | // Semtech radio definitions for SX127x, SX126x and SX128x |
LoRaToolbox | 1:b277f5a65c1c | 4 | |
LoRaToolbox | 0:44fb2db84011 | 5 | #if defined(SX127x_H) |
LoRaToolbox | 0:44fb2db84011 | 6 | #define BW_KHZ 500 |
LoRaToolbox | 0:44fb2db84011 | 7 | #define SPREADING_FACTOR 11 |
LoRaToolbox | 0:44fb2db84011 | 8 | #define CF_HZ 912000000 |
LoRaToolbox | 0:44fb2db84011 | 9 | #define TX_DBM 20 |
LoRaToolbox | 0:44fb2db84011 | 10 | #elif defined(SX126x_H) |
LoRaToolbox | 0:44fb2db84011 | 11 | #define BW_KHZ 500 |
LoRaToolbox | 0:44fb2db84011 | 12 | #define SPREADING_FACTOR 10 |
LoRaToolbox | 0:44fb2db84011 | 13 | #define CF_HZ 915000000 |
LoRaToolbox | 0:44fb2db84011 | 14 | #define TX_DBM (Radio::chipType == CHIP_TYPE_SX1262 ? 20 : 14) |
LoRaToolbox | 0:44fb2db84011 | 15 | #elif defined(SX128x_H) |
LoRaToolbox | 0:44fb2db84011 | 16 | #define BW_KHZ 200 |
LoRaToolbox | 0:44fb2db84011 | 17 | #define SPREADING_FACTOR 7 |
LoRaToolbox | 0:44fb2db84011 | 18 | #define CF_HZ 2487000000 |
LoRaToolbox | 0:44fb2db84011 | 19 | #define TX_DBM 6 |
LoRaToolbox | 0:44fb2db84011 | 20 | #endif |
LoRaToolbox | 0:44fb2db84011 | 21 | |
LoRaToolbox | 1:b277f5a65c1c | 22 | /******************** Setup radio transmitter ****************************/ |
LoRaToolbox | 1:b277f5a65c1c | 23 | |
LoRaToolbox | 1:b277f5a65c1c | 24 | |
LoRaToolbox | 0:44fb2db84011 | 25 | volatile bool txDone; |
LoRaToolbox | 0:44fb2db84011 | 26 | |
LoRaToolbox | 0:44fb2db84011 | 27 | void txDoneCB() |
LoRaToolbox | 0:44fb2db84011 | 28 | { |
LoRaToolbox | 0:44fb2db84011 | 29 | txDone = true; |
LoRaToolbox | 0:44fb2db84011 | 30 | } |
LoRaToolbox | 0:44fb2db84011 | 31 | |
LoRaToolbox | 0:44fb2db84011 | 32 | void rxDoneCB(uint8_t size, float rssi, float snr) |
LoRaToolbox | 0:44fb2db84011 | 33 | { |
LoRaToolbox | 0:44fb2db84011 | 34 | } |
LoRaToolbox | 0:44fb2db84011 | 35 | |
LoRaToolbox | 1:b277f5a65c1c | 36 | // Define radio events for transmitter |
LoRaToolbox | 1:b277f5a65c1c | 37 | |
LoRaToolbox | 0:44fb2db84011 | 38 | const RadioEvents_t rev = { |
LoRaToolbox | 0:44fb2db84011 | 39 | /* Dio0_top_half */ NULL, |
LoRaToolbox | 0:44fb2db84011 | 40 | /* TxDone_topHalf */ NULL, |
LoRaToolbox | 0:44fb2db84011 | 41 | /* TxDone_botHalf */ txDoneCB, |
LoRaToolbox | 0:44fb2db84011 | 42 | /* TxTimeout */ NULL, |
LoRaToolbox | 0:44fb2db84011 | 43 | /* RxDone */ rxDoneCB, |
LoRaToolbox | 0:44fb2db84011 | 44 | /* RxTimeout */ NULL, |
LoRaToolbox | 0:44fb2db84011 | 45 | /* RxError */ NULL, |
LoRaToolbox | 0:44fb2db84011 | 46 | /* FhssChangeChannel */NULL, |
LoRaToolbox | 0:44fb2db84011 | 47 | /* CadDone */ NULL |
LoRaToolbox | 0:44fb2db84011 | 48 | }; |
LoRaToolbox | 0:44fb2db84011 | 49 | |
LoRaToolbox | 0:44fb2db84011 | 50 | int main() |
LoRaToolbox | 0:44fb2db84011 | 51 | { |
LoRaToolbox | 1:b277f5a65c1c | 52 | uint8_t seq = 0; // Set initial transmit sequence to 0 |
LoRaToolbox | 1:b277f5a65c1c | 53 | |
LoRaToolbox | 0:44fb2db84011 | 54 | printf("\r\nreset-tx "); |
LoRaToolbox | 1:b277f5a65c1c | 55 | |
LoRaToolbox | 1:b277f5a65c1c | 56 | // Start radio transmitter after POR or reset |
LoRaToolbox | 0:44fb2db84011 | 57 | |
LoRaToolbox | 0:44fb2db84011 | 58 | Radio::Init(&rev); |
LoRaToolbox | 0:44fb2db84011 | 59 | |
LoRaToolbox | 1:b277f5a65c1c | 60 | //Set radio properties for transmitter |
LoRaToolbox | 1:b277f5a65c1c | 61 | |
LoRaToolbox | 0:44fb2db84011 | 62 | Radio::Standby(); |
LoRaToolbox | 0:44fb2db84011 | 63 | Radio::LoRaModemConfig(BW_KHZ, SPREADING_FACTOR, 1); |
LoRaToolbox | 0:44fb2db84011 | 64 | Radio::SetChannel(CF_HZ); |
LoRaToolbox | 0:44fb2db84011 | 65 | |
LoRaToolbox | 1:b277f5a65c1c | 66 | // Set transmitter output power |
LoRaToolbox | 1:b277f5a65c1c | 67 | |
LoRaToolbox | 0:44fb2db84011 | 68 | Radio::set_tx_dbm(TX_DBM); |
LoRaToolbox | 0:44fb2db84011 | 69 | |
LoRaToolbox | 1:b277f5a65c1c | 70 | // Setup transmit packet payload -> preambleLen, fixLen, crcOn, invIQ |
LoRaToolbox | 1:b277f5a65c1c | 71 | |
LoRaToolbox | 0:44fb2db84011 | 72 | Radio::LoRaPacketConfig(8, false, true, false); |
LoRaToolbox | 0:44fb2db84011 | 73 | |
LoRaToolbox | 0:44fb2db84011 | 74 | printf("\n"); |
LoRaToolbox | 0:44fb2db84011 | 75 | |
LoRaToolbox | 0:44fb2db84011 | 76 | printf("%02d \r\n\n", seq); |
LoRaToolbox | 0:44fb2db84011 | 77 | |
LoRaToolbox | 0:44fb2db84011 | 78 | for (;;) { |
LoRaToolbox | 1:b277f5a65c1c | 79 | Radio::radio.tx_buf[0] = seq; // set payload |
LoRaToolbox | 0:44fb2db84011 | 80 | txDone = false; |
LoRaToolbox | 1:b277f5a65c1c | 81 | Radio::Send(10, 0, 0, 0); // begin transmission of payload |
LoRaToolbox | 0:44fb2db84011 | 82 | |
LoRaToolbox | 0:44fb2db84011 | 83 | while (!txDone) { |
LoRaToolbox | 0:44fb2db84011 | 84 | Radio::service(); |
LoRaToolbox | 0:44fb2db84011 | 85 | } |
LoRaToolbox | 0:44fb2db84011 | 86 | |
LoRaToolbox | 1:b277f5a65c1c | 87 | // Transmit payload every 500mS |
LoRaToolbox | 0:44fb2db84011 | 88 | |
LoRaToolbox | 1:b277f5a65c1c | 89 | wait(0.5); // throttle sending rate |
LoRaToolbox | 1:b277f5a65c1c | 90 | seq++; // change payload (increment sequence number) |
LoRaToolbox | 1:b277f5a65c1c | 91 | printf("%02d \r\n\n", seq); // Print sequence number |
LoRaToolbox | 0:44fb2db84011 | 92 | |
LoRaToolbox | 1:b277f5a65c1c | 93 | } |
LoRaToolbox | 0:44fb2db84011 | 94 | } |