wayne roberts
/
simple_rx
Basic LoRa receiver example
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "radio.h" 00002 00003 #if defined(SX128x_H) 00004 #define BW_KHZ 200 00005 #define SPREADING_FACTOR 7 00006 #define CF_HZ 2487000000 00007 #define TX_DBM 6 00008 #else 00009 #if defined(SX128x_H) 00010 #define TX_DBM (Radio::chipType == CHIP_TYPE_SX1262 ? 20 : 14) 00011 #else 00012 #define TX_DBM 20 00013 #endif 00014 #define BW_KHZ 125 00015 #define SPREADING_FACTOR 7 00016 #define CF_HZ 915000000 00017 #endif 00018 00019 DigitalOut myled(LED1); 00020 00021 /**********************************************************************/ 00022 00023 void txDoneCB() 00024 { 00025 } 00026 00027 void rxDoneCB(uint8_t size, float rssi, float snr) 00028 { 00029 unsigned i; 00030 printf("%.1fdBm snr:%.1fdB\t", rssi, snr); 00031 00032 myled.write(!myled.read()); // toggle LED 00033 00034 for (i = 0; i < size; i++) { 00035 printf("%02x ", Radio::radio.rx_buf[i]); 00036 } 00037 printf("\r\n"); 00038 } 00039 00040 const RadioEvents_t rev = { 00041 /* Dio0_top_half */ NULL, 00042 /* TxDone_topHalf */ NULL, 00043 /* TxDone_botHalf */ txDoneCB, 00044 /* TxTimeout */ NULL, 00045 /* RxDone */ rxDoneCB, 00046 /* RxTimeout */ NULL, 00047 /* RxError */ NULL, 00048 /* FhssChangeChannel */NULL, 00049 /* CadDone */ NULL 00050 }; 00051 00052 int main() 00053 { 00054 printf("\r\nreset-rx\r\n"); 00055 00056 Radio::Init(&rev); 00057 00058 Radio::Standby(); 00059 Radio::LoRaModemConfig(BW_KHZ, SPREADING_FACTOR, 1); 00060 Radio::SetChannel(CF_HZ); 00061 00062 // preambleLen, fixLen, crcOn, invIQ 00063 Radio::LoRaPacketConfig(8, false, true, false); 00064 00065 Radio::Rx(0); 00066 00067 for (;;) { 00068 Radio::service(); 00069 } 00070 } 00071
Generated on Wed Jul 13 2022 01:20:27 by 1.7.2