Test Commit

Dependencies:   sx126x

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "sx12xx.h"
00002 
00003 DigitalOut myled(LED1);
00004 
00005 #ifdef TARGET_FF_ARDUINO    /* pins of SX126xDVK1xAS board */
00006     SPI spi(D11, D12, D13); // mosi, miso, sclk
00007                    //spi, nss, busy, dio1
00008     SX126x radio(spi, D7, D3, D5);
00009 
00010     #define CHIP_TYPE_SX1262        0
00011     #define CHIP_TYPE_SX1261        1
00012     DigitalIn chipType(A2);
00013     AnalogIn xtalSel(A3);
00014     DigitalOut antswPower(D8);
00015 #endif /* TARGET_FF_ARDUINO */
00016 
00017 /**********************************************************************/
00018 
00019 void rx_done(uint8_t size, float rssi, float snr)
00020 {
00021     unsigned i;
00022 
00023     myled.write(!myled.read()); // toggle LED
00024 
00025     printf("rssi:%.1fdBm, snr:%.1fdB   ", rssi, snr);
00026     for (i = 0; i < size; i++) {
00027         printf("%02x ", radio.rx_buf[i]);
00028     }
00029     printf("\r\n");
00030 }
00031 
00032 
00033 int main()
00034 {   
00035     printf("\r\nreset-rx\r\n");
00036     
00037     radio.setStandby(STBY_XOSC);
00038     radio.setPacketType(PACKET_TYPE_LORA);
00039     radio.setMHz(915.0); 
00040 
00041     {
00042         ModulationParams_t mp;
00043 
00044         mp.lora.spreadingFactor = 7;
00045         mp.lora.bandwidth = LORA_BW_125;
00046         mp.lora.codingRate = LORA_CR_4_5;
00047         mp.lora.LowDatarateOptimize = 0;
00048 
00049         radio.xfer(OPCODE_SET_MODULATION_PARAMS, 4, mp.buf);
00050     }
00051 
00052     {    
00053         PacketParams_t p;
00054 
00055         p.lora.PreambleLengthHi = 0;
00056         p.lora.PreambleLengthLo = 8;
00057         p.lora.HeaderType = HEADER_TYPE_VARIABLE_LENGTH;
00058         p.lora.PayloadLength = 0x40;    // max limit in rx
00059         p.lora.CRCType = CRC_ON;
00060         p.lora.InvertIQ = STANDARD_IQ;
00061 
00062         radio.xfer(OPCODE_SET_PACKET_PARAMS, 6, p.buf);
00063     }
00064     
00065     antswPower = 1;
00066     radio.SetDIO2AsRfSwitchCtrl(1);
00067 
00068     radio.rxDone = rx_done;
00069 
00070     radio.start_rx(RX_TIMEOUT_CONTINUOUS);
00071     
00072      for (;;) {  
00073      
00074 //     PacketParams_t p;
00075 
00076  //       p.lora.PreambleLengthHi = 0;
00077   //      p.lora.PreambleLengthLo = 8;
00078   //      p.lora.HeaderType = HEADER_TYPE_VARIABLE_LENGTH;
00079   //      p.lora.PayloadLength = 0x40;    // max limit in rx
00080   //      p.lora.CRCType = CRC_ON;
00081   //      p.lora.InvertIQ = STANDARD_IQ;
00082 
00083  //       radio.xfer(OPCODE_SET_PACKET_PARAMS, 6, p.buf);
00084      
00085     
00086           
00087         radio.service();
00088          uint8_t buf[2];
00089         buf[0] = 0; // TX base address
00090         buf[1] = 0; // RX base address
00091       radio.xfer(OPCODE_SET_BUFFER_BASE_ADDR, 2, buf);
00092     }
00093 }