12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163 |
- #if MUTEX==1
- void CreateMutux(int *mutex) {
- *mutex=1;
- }
- #define LIB_MUTEX 1
- #if LIB_MUTEX==1
- bool GetMutex(int *mutex) {
-
- if (*mutex==1) {
- *mutex=0;
-
- return(true);
- }
-
- return(false);
- }
- #else
- bool GetMutex(int *mutex) {
- int iOld = 1, iNew = 0;
- asm volatile (
- "rsil a15, 1\n"
- "l32i %0, %1, 0\n"
- "bne %0, %2, 1f\n"
- "s32i %3, %1, 0\n"
- "1:\n"
- "wsr.ps a15\n"
- "rsync\n"
- : "=&r" (iOld)
- : "r" (mutex), "r" (iOld), "r" (iNew)
- : "a15", "memory"
- );
- return (bool)iOld;
- }
- #endif
- void ReleaseMutex(int *mutex) {
- *mutex=1;
- }
-
- #endif
- SPISettings readSettings(SPISPEED, MSBFIRST, SPI_MODE0);
- uint8_t readRegister(uint8_t addr)
- {
- SPI.beginTransaction(readSettings);
- digitalWrite(pins.ss, LOW);
- SPI.transfer(addr & 0x7F);
- uint8_t res = (uint8_t) SPI.transfer(0x00);
- digitalWrite(pins.ss, HIGH);
- SPI.endTransaction();
- return((uint8_t) res);
- }
- SPISettings writeSettings(SPISPEED, MSBFIRST, SPI_MODE0);
- void writeRegister(uint8_t addr, uint8_t value)
- {
- SPI.beginTransaction(writeSettings);
- digitalWrite(pins.ss, LOW);
-
- SPI.transfer((addr | 0x80) & 0xFF);
- SPI.transfer(value & 0xFF);
-
- digitalWrite(pins.ss, HIGH);
-
- SPI.endTransaction();
- }
- void writeBuffer(uint8_t addr, uint8_t *buf, uint8_t len)
- {
-
-
- SPI.beginTransaction(writeSettings);
- digitalWrite(pins.ss, LOW);
-
- SPI.transfer((addr | 0x80) & 0xFF);
- for (uint8_t i=0; i<len; i++) {
- SPI.transfer(buf[i] & 0xFF);
- }
- digitalWrite(pins.ss, HIGH);
-
- SPI.endTransaction();
- }
- void setRate(uint8_t sf, uint8_t crc)
- {
- uint8_t mc1=0, mc2=0, mc3=0;
- # if _MONITOR>=2
- if ((sf<SF7) || (sf>SF12)) {
- if (( debug>=1 ) && ( pdebug & P_RADIO )) {
- mPrint("setRate:: SF=" + String(sf));
- }
- return;
- }
- # endif
-
- if (sx1272) {
- mc1= 0x0A;
- mc2= ((sf<<4) | crc) % 0xFF;
-
- if (sf == SF11 || sf == SF12) {
- mc1= 0x0B;
- }
- }
-
-
- else {
- uint8_t bw = 0;
- uint8_t cr = 0;
-
-
- if (sf==SF8) {
- mc1= 0x78;
- }
- else {
- mc1= 0x72;
- }
- mc2= ((sf<<4) | crc) & 0xFF;
- mc3= 0x04;
- if (sf == SF11 || sf == SF12) { mc3|= 0x08; }
- }
-
-
-
-
-
-
-
- writeRegister(REG_MODEM_CONFIG1, (uint8_t) mc1);
- writeRegister(REG_MODEM_CONFIG2, (uint8_t) mc2);
- writeRegister(REG_MODEM_CONFIG3, (uint8_t) mc3);
-
-
- if (sf == SF10 || sf == SF11 || sf == SF12) {
- writeRegister(REG_SYMB_TIMEOUT_LSB, (uint8_t) 0x05);
- } else {
- writeRegister(REG_SYMB_TIMEOUT_LSB, (uint8_t) 0x08);
- }
- return;
- }
- void setFreq(uint32_t freq)
- {
-
- uint64_t frf = ((uint64_t)freq << 19) / 32000000;
- writeRegister(REG_FRF_MSB, (uint8_t)(frf>>16) );
- writeRegister(REG_FRF_MID, (uint8_t)(frf>> 8) );
- writeRegister(REG_FRF_LSB, (uint8_t)(frf>> 0) );
-
- return;
- }
- void setPow(uint8_t powe)
- {
- if (powe >= 16) powe = 15;
-
- else if (powe < 2) powe =2;
-
- ASSERT((powe>=2)&&(powe<=15));
-
- uint8_t pac = (0x80 | (powe & 0xF)) & 0xFF;
- writeRegister(REG_PAC, (uint8_t)pac);
-
-
-
- return;
- }
- void opmode(uint8_t mode)
- {
- if (mode == OPMODE_LORA)
- writeRegister(REG_OPMODE, (uint8_t) mode);
- else
- writeRegister(REG_OPMODE, (uint8_t)((readRegister(REG_OPMODE) & ~OPMODE_MASK) | mode));
- }
- void hop() {
-
- opmode(OPMODE_STANDBY);
-
-
- ifreq = (ifreq + 1) % NUM_HOPS ;
- setFreq(freqs[ifreq].upFreq);
-
-
- sf = SF7;
- setRate(sf, 0x40);
-
-
- writeRegister(REG_LNA, (uint8_t) LNA_MAX_GAIN);
-
-
- writeRegister(REG_SYNC_WORD, (uint8_t) 0x34);
-
-
- writeRegister(REG_INVERTIQ,0x27);
-
-
-
- writeRegister(REG_MAX_PAYLOAD_LENGTH,MAX_PAYLOAD_LENGTH);
- writeRegister(REG_PAYLOAD_LENGTH,PAYLOAD_LENGTH);
-
- writeRegister(REG_FIFO_ADDR_PTR, (uint8_t) readRegister(REG_FIFO_RX_BASE_AD));
- writeRegister(REG_HOP_PERIOD,0x00);
-
- writeRegister(REG_PARAMP, (readRegister(REG_PARAMP) & 0xF0) | 0x08);
-
-
- writeRegister(REG_PADAC_SX1276, 0x84);
-
-
- writeRegister(REG_IRQ_FLAGS_MASK, 0x00);
-
-
- writeRegister(REG_IRQ_FLAGS, 0xFF);
-
-
-
-
- # if _MONITOR>=1
- if (( debug>=2 ) && ( pdebug & P_RADIO )){
- String response = "hop:: hopTime:: " + String(micros() - hopTime);
- mStat(0, response);
- mPrint(response);
- }
- # endif
-
- hopTime = micros();
- }
-
- uint8_t receivePkt(uint8_t *payload)
- {
- statc.msg_ttl++;
- uint8_t irqflags = readRegister(REG_IRQ_FLAGS);
- uint8_t crcUsed = readRegister(REG_HOP_CHANNEL);
- if (crcUsed & 0x40) {
- # if _DUSB>=1
- if (( debug>=2) && (pdebug & P_RX )) {
- Serial.println(F("R rxPkt:: CRC used"));
- }
- # endif
- }
-
-
- if (irqflags & IRQ_LORA_CRCERR_MASK)
- {
- # if _DUSB>=1
- if (( debug>=0) && ( pdebug & P_RADIO )) {
- Serial.print(F("rxPkt:: Err CRC, t="));
- SerialTime();
- Serial.println();
- }
- # endif
- return 0;
- }
-
-
-
-
- else if ((irqflags & IRQ_LORA_HEADER_MASK) == false)
- {
- # if _DUSB>=1
- if (( debug>=0) && ( pdebug & P_RADIO )) {
- Serial.println(F("rxPkt:: Err HEADER"));
- }
- # endif
-
- writeRegister(REG_IRQ_FLAGS, (uint8_t)(IRQ_LORA_HEADER_MASK | IRQ_LORA_RXDONE_MASK));
- return 0;
- }
-
-
-
- else {
- statc.msg_ok++;
- switch(statr[0].ch) {
- case 0: statc.msg_ok_0++; break;
- case 1: statc.msg_ok_1++; break;
- case 2: statc.msg_ok_2++; break;
- }
- if (readRegister(REG_FIFO_RX_CURRENT_ADDR) != readRegister(REG_FIFO_RX_BASE_AD)) {
- #if _DUSB>=1
- if (( debug>=1 ) && ( pdebug & P_RADIO )) {
- Serial.print(F("RX BASE <"));
- Serial.print(readRegister(REG_FIFO_RX_BASE_AD));
- Serial.print(F("> != RX CURRENT <"));
- Serial.print(readRegister(REG_FIFO_RX_CURRENT_ADDR));
- Serial.print(F(">"));
- Serial.println();
- }
- # endif
- }
-
-
- uint8_t currentAddr = readRegister(REG_FIFO_RX_BASE_AD);
- uint8_t receivedCount = readRegister(REG_RX_NB_BYTES);
- # if _DUSB>=1
- if ((debug>=1) && (currentAddr > 64)) {
- Serial.print(F("rxPkt:: Rx addr>64"));
- Serial.println(currentAddr);
- }
- # endif
- writeRegister(REG_FIFO_ADDR_PTR, (uint8_t) currentAddr);
- if (receivedCount > PAYLOAD_LENGTH) {
- # if _DUSB>=1
- if (( debug>=1 ) & ( pdebug & P_RADIO )) {
- Serial.print(F("rxPkt:: receivedCount="));
- Serial.println(receivedCount);
- }
- # endif
- receivedCount=PAYLOAD_LENGTH;
- }
- for(int i=0; i < receivedCount; i++)
- {
- payload[i] = readRegister(REG_FIFO);
- }
- writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF);
-
-
-
- # if _DUSB>=1
- if (( debug>=1 ) && ( pdebug & P_RX )){
-
- Serial.print(F("rxPkt:: t="));
- SerialTime();
-
- Serial.print(F(", f="));
- Serial.print(ifreq);
- Serial.print(F(", sf="));
- Serial.print(sf);
- Serial.print(F(", a="));
- if (payload[4]<0x10) Serial.print('0'); Serial.print(payload[4], HEX);
- if (payload[3]<0x10) Serial.print('0'); Serial.print(payload[3], HEX);
- if (payload[2]<0x10) Serial.print('0'); Serial.print(payload[2], HEX);
- if (payload[1]<0x10) Serial.print('0'); Serial.print(payload[1], HEX);
- Serial.print(F(", flags="));
- Serial.print(irqflags,HEX);
- Serial.print(F(", addr="));
- Serial.print(currentAddr);
- Serial.print(F(", len="));
- Serial.print(receivedCount);
-
-
- # if _TRUSTED_DECODE>=2
- if (debug>=1) {
- int index;
- String response="";
- uint8_t data[receivedCount];
-
- uint8_t DevAddr [4];
- DevAddr[0] = payload[4];
- DevAddr[1] = payload[3];
- DevAddr[2] = payload[2];
- DevAddr[3] = payload[1];
-
- if ((index = inDecodes((char *)(payload+1))) >=0 ) {
- Serial.print(F(", Ind="));
- Serial.print(index);
-
- }
- else if (debug>=1) {
- Serial.print(F(", No Index"));
- Serial.println();
- return(receivedCount);
- }
-
-
- Serial.print(F(", data="));
- for (int i=0; i<receivedCount; i++) {
- data[i] = payload[i];
- }
- uint16_t frameCount=payload[7]*256 + payload[6];
-
-
-
- uint8_t CodeLength = encodePacket((uint8_t *)(data + 9), receivedCount-9-4, (uint16_t)frameCount, DevAddr, decodes[index].appKey, 0);
- Serial.print(F("- NEW fc="));
- Serial.print(frameCount);
- Serial.print(F(", addr="));
-
- for (int i=0; i<4; i++) {
- if (DevAddr[i]<=0xF) {
- Serial.print('0');
- }
- Serial.print(DevAddr[i], HEX);
- Serial.print(' ');
- }
-
- Serial.print(F(", len="));
- Serial.print(CodeLength);
- Serial.print(F(", data="));
- for (int i=0; i<receivedCount; i++) {
- if (data[i]<=0xF) Serial.print('0');
- Serial.print(data[i], HEX);
- Serial.print(' ');
- }
- |
- # endif
-
- Serial.println();
-
- if (debug>=2) Serial.flush();
- }
- # endif
- return(receivedCount);
- }
- writeRegister(REG_IRQ_FLAGS, (uint8_t) (
- IRQ_LORA_RXDONE_MASK |
- IRQ_LORA_RXTOUT_MASK |
- IRQ_LORA_HEADER_MASK |
- IRQ_LORA_CRCERR_MASK));
- return 0;
- }
-
-
-
- bool sendPkt(uint8_t *payLoad, uint8_t payLength)
- {
- # if _DUSB>=2
- if (payLength>=128) {
- if (debug>=1) {
- Serial.print("sendPkt:: len=");
- Serial.println(payLength);
- }
- return false;
- }
- # endif
-
- writeRegister(REG_FIFO_ADDR_PTR, (uint8_t) readRegister(REG_FIFO_TX_BASE_AD));
-
- writeRegister(REG_PAYLOAD_LENGTH, (uint8_t) payLength);
- payLoad[payLength] = 0x00;
- writeBuffer(REG_FIFO, (uint8_t *) payLoad, payLength);
-
- return true;
- }
- void loraWait(const uint32_t timestamp)
- {
- uint32_t startMics = micros();
- uint32_t tmst = timestamp;
- int32_t adjust=0;
- switch (LoraDown.sfTx) {
- case 7: adjust= 60000; break;
- case 8: break;
- case 9: break;
- case 10: break;
- case 11: break;
- case 12: break;
- default:
- # if _DUSB>=1
- if (( debug>=1 ) && ( pdebug & P_TX )) {
- Serial.print(F("T loraWait:: unknown SF="));
- Serial.print(LoraDown.sfTx);
- }
- # endif
- break;
- }
- tmst = tmst + gwayConfig.txDelay + adjust;
- uint32_t waitTime = tmst - micros();
- if (micros()>tmst) {
- Serial.println(F("loraWait:: Error wait time < 0"));
- return;
- }
-
-
-
- while (waitTime > 16000) {
- delay(15);
- waitTime= tmst - micros();
- }
-
-
- if (waitTime>0) delayMicroseconds(waitTime);
- # if _DUSB>=1
- else if ((waitTime+20) < 0) {
- Serial.println(F("loraWait:: TOO LATE"));
- }
- if (( debug>=2 ) && ( pdebug & P_TX )) {
- Serial.print(F("T start: "));
- Serial.print(startMics);
- Serial.print(F(", tmst: "));
- Serial.print(tmst);
- Serial.print(F(", end: "));
- Serial.print(micros());
- Serial.print(F(", waited: "));
- Serial.print(tmst - startMics);
- Serial.print(F(", delay="));
- Serial.print(gwayConfig.txDelay);
- Serial.println();
- if (debug>=2) Serial.flush();
- }
- # endif
- }
- void txLoraModem(
- uint8_t *payLoad,
- uint8_t payLength,
- uint32_t tmst,
- uint8_t sfTx,
- uint8_t powe,
- uint32_t freq,
- uint8_t crc,
- uint8_t iiq
- )
- {
- # if _DUSB>=2
- if (debug>=1) {
-
- Serial.print(F("txLoraModem::"));
- Serial.print(F(" powe: ")); Serial.print(powe);
- Serial.print(F(", freq: ")); Serial.print(freq);
- Serial.print(F(", crc: ")); Serial.print(crc);
- Serial.print(F(", iiq: 0X")); Serial.print(iiq,HEX);
- Serial.println();
- if (debug>=2) Serial.flush();
- }
- # endif
- _state = S_TX;
-
-
-
-
-
- ASSERT((readRegister(REG_OPMODE) & OPMODE_LORA) != 0);
-
-
- opmode(OPMODE_STANDBY);
-
-
- setRate(sfTx, crc);
-
-
-
-
-
- setFreq(freq);
-
- setPow(powe);
-
-
- writeRegister(REG_INVERTIQ, (uint8_t) iiq);
-
-
- writeRegister(REG_DIO_MAPPING_1, (uint8_t)(
- MAP_DIO0_LORA_TXDONE |
- MAP_DIO1_LORA_NOP |
- MAP_DIO2_LORA_NOP |
- MAP_DIO3_LORA_CRC));
-
-
- writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF);
-
-
- writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) ~IRQ_LORA_TXDONE_MASK);
-
-
- opmode(OPMODE_FSTX);
-
-
- sendPkt(payLoad, payLength);
-
- loraWait(tmst);
-
-
- writeRegister(REG_FIFO_ADDR_PTR, (uint8_t) readRegister(REG_FIFO_TX_BASE_AD));
-
-
- writeRegister(REG_PAYLOAD_LENGTH, (uint8_t) payLength);
-
-
- writeRegister(REG_MAX_PAYLOAD_LENGTH, (uint8_t) MAX_PAYLOAD_LENGTH);
-
-
- writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00);
- writeRegister(REG_IRQ_FLAGS, (uint8_t) IRQ_LORA_TXDONE_MASK);
-
-
- opmode(OPMODE_TX);
-
- }
- void rxLoraModem()
- {
-
-
-
-
- opmode(OPMODE_STANDBY);
-
-
- setFreq(freqs[ifreq].upFreq);
-
- setRate(sf, 0x04);
-
-
- writeRegister(REG_INVERTIQ, (uint8_t) 0x27);
-
-
-
-
-
-
-
-
-
- writeRegister(REG_FIFO_ADDR_PTR, (uint8_t) readRegister(REG_FIFO_RX_BASE_AD));
-
-
- writeRegister(REG_LNA, (uint8_t) LNA_MAX_GAIN);
-
-
- writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) ~(
- IRQ_LORA_RXDONE_MASK |
- IRQ_LORA_RXTOUT_MASK |
- IRQ_LORA_HEADER_MASK |
- IRQ_LORA_CRCERR_MASK));
-
- if (_hop) {
-
- writeRegister(REG_HOP_PERIOD,0x00);
- }
- else {
- writeRegister(REG_HOP_PERIOD,0x00);
- }
-
- writeRegister(REG_DIO_MAPPING_1, (uint8_t)(
- MAP_DIO0_LORA_RXDONE |
- MAP_DIO1_LORA_RXTOUT |
- MAP_DIO2_LORA_NOP |
- MAP_DIO3_LORA_CRC));
-
-
- if (_cad) {
-
-
- _state= S_RX;
- opmode(OPMODE_RX_SINGLE);
- }
- else {
-
- _state= S_RX;
- # if _DUSB>=1
- if (_hop) {
- Serial.println(F("rxLoraModem:: ERROR continuous receive in hop mode"));
- }
- # endif
- opmode(OPMODE_RX);
- }
-
-
- writeRegister(REG_IRQ_FLAGS, 0xFF);
-
- return;
- }
- void cadScanner()
- {
-
-
-
-
- opmode(OPMODE_STANDBY);
-
-
- setFreq(freqs[ifreq].upFreq);
-
-
-
-
- setRate(sf, 0x04);
-
-
- writeRegister(REG_SYNC_WORD, (uint8_t) 0x34);
-
-
- writeRegister(REG_DIO_MAPPING_1, (uint8_t)(
- MAP_DIO0_LORA_CADDONE |
- MAP_DIO1_LORA_CADDETECT |
- MAP_DIO2_LORA_NOP |
- MAP_DIO3_LORA_CRC ));
-
-
- writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) ~(
- IRQ_LORA_CDDONE_MASK |
- IRQ_LORA_CDDETD_MASK |
- IRQ_LORA_CRCERR_MASK |
- IRQ_LORA_HEADER_MASK));
-
-
- opmode(OPMODE_CAD);
-
-
-
-
-
- return;
-
- }
- void initLoraModem(
- )
- {
- _state = S_INIT;
- #if ESP32_ARCH==1
- digitalWrite(pins.rst, LOW);
- delayMicroseconds(10000);
- digitalWrite(pins.rst, HIGH);
- delayMicroseconds(10000);
- digitalWrite(pins.ss, HIGH);
- #else
-
- digitalWrite(pins.rst, HIGH);
- delayMicroseconds(10000);
- digitalWrite(pins.rst, LOW);
- delayMicroseconds(10000);
- #endif
-
- opmode(OPMODE_SLEEP);
-
- opmode(OPMODE_LORA);
-
-
- setFreq(freqs[ifreq].upFreq);
-
-
- setRate(sf, 0x04);
-
-
- writeRegister(REG_LNA, (uint8_t) LNA_MAX_GAIN);
- # if _PIN_OUT==4
- delay(1);
- # endif
-
- uint8_t version = readRegister(REG_VERSION);
- if (version == 0x22) {
-
- # if _DUSB>=2
- Serial.println(F("WARNING:: SX1272 detected"));
- # endif
- sx1272 = true;
- }
-
- else if (version == 0x12) {
-
- # if _DUSB>=2
- if (debug >=1)
- Serial.println(F("SX1276 starting"));
- # endif
- sx1272 = false;
- }
- else {
-
-
-
-
- # if _DUSB>=1
- Serial.print(F("Unknown transceiver="));
- Serial.print(version,HEX);
- Serial.print(F(", pins.rst =")); Serial.print(pins.rst);
- Serial.print(F(", pins.ss =")); Serial.print(pins.ss);
- Serial.print(F(", pins.dio0 =")); Serial.print(pins.dio0);
- Serial.print(F(", pins.dio1 =")); Serial.print(pins.dio1);
- Serial.print(F(", pins.dio2 =")); Serial.print(pins.dio2);
- Serial.println();
- Serial.flush();
- # endif
- die("");
- }
-
-
-
- writeRegister(REG_SYNC_WORD, (uint8_t) 0x34);
-
-
- writeRegister(REG_INVERTIQ,0x27);
-
-
-
- writeRegister(REG_MAX_PAYLOAD_LENGTH,MAX_PAYLOAD_LENGTH);
- writeRegister(REG_PAYLOAD_LENGTH,PAYLOAD_LENGTH);
-
- writeRegister(REG_FIFO_ADDR_PTR, (uint8_t) readRegister(REG_FIFO_RX_BASE_AD));
- writeRegister(REG_HOP_PERIOD,0x00);
-
- writeRegister(REG_PARAMP, (readRegister(REG_PARAMP) & 0xF0) | 0x08);
-
-
- writeRegister(REG_PADAC_SX1276, 0x84);
-
-
-
- writeRegister(REG_IRQ_FLAGS_MASK, 0x00);
-
-
- writeRegister(REG_IRQ_FLAGS, 0xFF);
- }
- void startReceiver() {
- initLoraModem();
- if (_cad) {
- # if _DUSB>=1
- if (( debug>=1 ) && ( pdebug & P_SCAN )) {
- Serial.println(F("S PULL:: _state set to S_SCAN"));
- if (debug>=2) Serial.flush();
- }
- # endif
- _state = S_SCAN;
- sf = SF7;
- cadScanner();
- }
- else {
- _state = S_RX;
- rxLoraModem();
- }
- writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00);
- writeRegister(REG_IRQ_FLAGS, 0xFF);
- }
- void ICACHE_RAM_ATTR Interrupt_0()
- {
- _event=1;
- }
- void ICACHE_RAM_ATTR Interrupt_1()
- {
- _event=1;
- }
- void ICACHE_RAM_ATTR Interrupt_2()
- {
- _event=1;
- }
|