Initial commit
Dependencies: SX127x sx12xx_hal
main.cpp
00001 #include "radio.h" 00002 00003 // Semtech radio definitions for SX127x, SX126x and SX128x 00004 00005 #if defined(SX127x_H) 00006 #define BW_KHZ 500 00007 #define SPREADING_FACTOR 11 00008 #define CF_HZ 912000000 00009 #define TX_DBM 20 00010 #elif defined(SX126x_H) 00011 #define BW_KHZ 500 00012 #define SPREADING_FACTOR 10 00013 #define CF_HZ 915000000 00014 #define TX_DBM (Radio::chipType == CHIP_TYPE_SX1262 ? 20 : 14) 00015 #elif defined(SX128x_H) 00016 #define BW_KHZ 200 00017 #define SPREADING_FACTOR 7 00018 #define CF_HZ 2487000000 00019 #define TX_DBM 6 00020 #endif 00021 00022 /******************** Setup radio transmitter ****************************/ 00023 00024 00025 volatile bool txDone; 00026 00027 void txDoneCB() 00028 { 00029 txDone = true; 00030 } 00031 00032 void rxDoneCB(uint8_t size, float rssi, float snr) 00033 { 00034 } 00035 00036 // Define radio events for transmitter 00037 00038 const RadioEvents_t rev = { 00039 /* Dio0_top_half */ NULL, 00040 /* TxDone_topHalf */ NULL, 00041 /* TxDone_botHalf */ txDoneCB, 00042 /* TxTimeout */ NULL, 00043 /* RxDone */ rxDoneCB, 00044 /* RxTimeout */ NULL, 00045 /* RxError */ NULL, 00046 /* FhssChangeChannel */NULL, 00047 /* CadDone */ NULL 00048 }; 00049 00050 int main() 00051 { 00052 uint8_t seq = 0; // Set initial transmit sequence to 0 00053 00054 printf("\r\nreset-tx "); 00055 00056 // Start radio transmitter after POR or reset 00057 00058 Radio::Init(&rev); 00059 00060 //Set radio properties for transmitter 00061 00062 Radio::Standby(); 00063 Radio::LoRaModemConfig(BW_KHZ, SPREADING_FACTOR, 1); 00064 Radio::SetChannel(CF_HZ); 00065 00066 // Set transmitter output power 00067 00068 Radio::set_tx_dbm(TX_DBM); 00069 00070 // Setup transmit packet payload -> preambleLen, fixLen, crcOn, invIQ 00071 00072 Radio::LoRaPacketConfig(8, false, true, false); 00073 00074 printf("\n"); 00075 00076 printf("%02d \r\n\n", seq); 00077 00078 for (;;) { 00079 Radio::radio.tx_buf[0] = seq; // set payload 00080 txDone = false; 00081 Radio::Send(10, 0, 0, 0); // begin transmission of payload 00082 00083 while (!txDone) { 00084 Radio::service(); 00085 } 00086 00087 // Transmit payload every 500mS 00088 00089 wait(0.5); // throttle sending rate 00090 seq++; // change payload (increment sequence number) 00091 printf("%02d \r\n\n", seq); // Print sequence number 00092 00093 } 00094 }
Generated on Fri Aug 26 2022 15:31:38 by 1.7.2