Loren Geilen
/
sx126x_simple_TX_shield_2020a
First Test Commit
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "sx12xx.h" 00002 #include "mbed.h" 00003 00004 #ifdef TARGET_FF_ARDUINO /* pins of SX126xDVK1xAS board */ 00005 SPI spi(D11, D12, D13); // mosi, miso, sclk 00006 // spi, nss, busy, dio1 00007 SX126x radio(spi, D7, D3, D5 ); 00008 #define CHIP_TYPE_SX1262 0 00009 #define CHIP_TYPE_SX1261 1 00010 DigitalIn chipType(A2); 00011 AnalogIn xtalSel(A3); 00012 DigitalOut antswPower(D8); 00013 #endif /* TARGET_FF_ARDUINO */ 00014 00015 Serial device(USBTX, USBRX); // tx, rx 00016 00017 /**********************************************************************/ 00018 volatile bool txDone; 00019 00020 void txDone_callback() 00021 { 00022 txDone = true; 00023 } 00024 00025 int main() 00026 { 00027 device.baud(57600); 00028 uint8_t seq = 0; 00029 00030 printf("\r\nreset-tx "); 00031 00032 radio.setStandby(STBY_XOSC); 00033 radio.setPacketType(PACKET_TYPE_LORA); 00034 radio.setMHz(915.5); 00035 00036 { 00037 ModulationParams_t mp; 00038 00039 mp.lora.spreadingFactor = 5; 00040 mp.lora.bandwidth = LORA_BW_500; 00041 mp.lora.codingRate = LORA_CR_4_5; 00042 mp.lora.LowDatarateOptimize = 0; 00043 00044 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 4, mp.buf); 00045 } 00046 00047 if (chipType == CHIP_TYPE_SX1262) 00048 radio.set_tx_dbm(true, 20); 00049 else 00050 radio.set_tx_dbm(false, 14); 00051 00052 00053 { 00054 PacketParams_t p; 00055 00056 p.lora.PreambleLengthHi = 0; 00057 p.lora.PreambleLengthLo = 8; 00058 p.lora.HeaderType = HEADER_TYPE_VARIABLE_LENGTH; 00059 /* constant payload length of one byte */ 00060 p.lora.PayloadLength = 1; 00061 p.lora.CRCType = CRC_ON; 00062 p.lora.InvertIQ = STANDARD_IQ; 00063 00064 radio.xfer(OPCODE_SET_PACKET_PARAMS, 6, p.buf); 00065 } 00066 00067 00068 antswPower = 1; 00069 radio.SetDIO2AsRfSwitchCtrl(1); 00070 00071 radio.txDone = txDone_callback; 00072 00073 for (;;) { 00074 radio.tx_buf[200] = seq; /* set payload */ 00075 txDone = false; 00076 radio.start_tx(1); /* begin transmission */ 00077 00078 printf("sent\r\n"); 00079 while (!txDone) { 00080 radio.service(); 00081 } 00082 00083 printf("got-tx-done\r\n"); 00084 00085 wait(0.5); /* throttle sending rate */ 00086 seq++; /* change payload */ 00087 } 00088 } 00089
Generated on Thu Jul 21 2022 23:57:20 by 1.7.2