acid-drop- Unnamed repository; edit this file 'description' to name the repository. |
git clone git://git.acid.vegas/-c.git |
Log | Files | Refs | Archive | README | LICENSE |
LoRa.cpp (2609B)
1 #include <RadioLib.h> 2 #include "pins.h" 3 4 5 SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN); 6 7 8 bool setupRadio() { 9 digitalWrite(BOARD_SDCARD_CS, HIGH); 10 digitalWrite(RADIO_CS_PIN, HIGH); 11 digitalWrite(BOARD_TFT_CS, HIGH); 12 SPI.end(); 13 SPI.begin(BOARD_SPI_SCK, BOARD_SPI_MISO, BOARD_SPI_MOSI); //SD 14 15 int state = radio.begin(RADIO_FREQ); 16 if (state == RADIOLIB_ERR_NONE) { 17 Serial.println("Start Radio success!"); 18 } else { 19 Serial.print("Start Radio failed,code:"); 20 Serial.println(state); 21 return false; 22 } 23 24 if (radio.setFrequency(RADIO_FREQ) == RADIOLIB_ERR_INVALID_FREQUENCY) { 25 Serial.println(F("Selected frequency is invalid for this module!")); 26 return false; 27 } 28 29 if (radio.setBandwidth(125.0) == RADIOLIB_ERR_INVALID_BANDWIDTH) { 30 Serial.println(F("Selected bandwidth is invalid for this module!")); 31 return false; 32 } 33 34 if (radio.setSpreadingFactor(10) == RADIOLIB_ERR_INVALID_SPREADING_FACTOR) { 35 Serial.println(F("Selected spreading factor is invalid for this module!")); 36 return false; 37 } 38 39 if (radio.setCodingRate(6) == RADIOLIB_ERR_INVALID_CODING_RATE) { 40 Serial.println(F("Selected coding rate is invalid for this module!")); 41 return false; 42 } 43 44 if (radio.setSyncWord(0xAB) != RADIOLIB_ERR_NONE) { 45 Serial.println(F("Unable to set sync word!")); 46 return false; 47 } 48 49 // set output power to 10 dBm (accepted range is -17 - 22 dBm) 50 if (radio.setOutputPower(17) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) { 51 Serial.println(F("Selected output power is invalid for this module!")); 52 return false; 53 } 54 55 // set over current protection limit to 140 mA (accepted range is 45 - 140 mA) (set value to 0 to disable overcurrent protection) 56 if (radio.setCurrentLimit(140) == RADIOLIB_ERR_INVALID_CURRENT_LIMIT) { 57 Serial.println(F("Selected current limit is invalid for this module!")); 58 return false; 59 } 60 61 // set LoRa preamble length to 15 symbols (accepted range is 0 - 65535) 62 if (radio.setPreambleLength(15) == RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH) { 63 Serial.println(F("Selected preamble length is invalid for this module!")); 64 return false; 65 } 66 67 if (radio.setCRC(false) == RADIOLIB_ERR_INVALID_CRC_CONFIGURATION) { 68 Serial.println(F("Selected CRC is invalid for this module!")); 69 return false; 70 } 71 72 // set the function that will be called when new packet is received 73 //radio.setDio1Action(setFlag); 74 75 return true; 76 }