Port of lowpowerlab RFM69 Packet radio library for HopeRF RFM69H with hacks from debugging with a FRDM-KL25Z
Fork of RFM69 by
Revision 7:ad10455a9b7b, committed 2016-06-27
- Comitter:
- eisd
- Date:
- Mon Jun 27 21:50:55 2016 +0000
- Parent:
- 6:34009020999c
- Commit message:
- IRQ for receive; no IRQ for send
Changed in this revision
RFM69.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 34009020999c -r ad10455a9b7b RFM69.cpp --- a/RFM69.cpp Sat Jun 25 07:10:52 2016 +0000 +++ b/RFM69.cpp Mon Jun 27 21:50:55 2016 +0000 @@ -61,7 +61,7 @@ // Setup the spi for 8 bit data, high steady state clock, // second edge capture, with a 1MHz clock rate _spi.format(8,0); - _spi.frequency(4000000); + _spi.frequency(1000000); _mode = RF69_MODE_STANDBY; _promiscuousMode = false; _powerLevel = 31; @@ -96,9 +96,9 @@ // RXBW defaults are { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_24 | RF_RXBW_EXP_5} (RxBw: 10.4KHz) /* 0x19 */ { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_16 | RF_RXBW_EXP_2 }, // (BitRate < 2 * RxBw) //for BR-19200: /* 0x19 */ { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_24 | RF_RXBW_EXP_3 }, - /* 0x25 */ { REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_01 }, // DIO0 is the only IRQ we're using + ///* 0x25 */ { REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_01 }, // DIO0 is the only IRQ we're using ///* 0x26 */ { REG_DIOMAPPING2, RF_DIOMAPPING2_CLKOUT_OFF }, // DIO5 ClkOut disable for power saving - /* 0x28 */ { REG_IRQFLAGS2, RF_IRQFLAGS2_FIFOOVERRUN }, // writing to this bit ensures that the FIFO & status flags are reset + ///* 0x28 */ { REG_IRQFLAGS2, RF_IRQFLAGS2_FIFOOVERRUN }, // writing to this bit ensures that the FIFO & status flags are reset /* 0x29 */ { REG_RSSITHRESH, 220 }, // must be set to dBm = (-Sensitivity / 2), default is 0xE4 = 228 so -114dBm /* 0x2D */ { REG_PREAMBLELSB, RF_PREAMBLESIZE_LSB_VALUE }, // default 3 preamble bytes 0xAAAAAA /* 0x2E */ { REG_SYNCCONFIG, RF_SYNC_ON | RF_SYNC_FIFOFILL_AUTO | RF_SYNC_SIZE_2 | RF_SYNC_TOL_0 }, @@ -120,18 +120,18 @@ // Setup the spi for 8 bit data : 1RW-bit 7 adressbit and 8 databit // second edge capture, with a 10MHz clock rate _spi.format(8,0); - _spi.frequency(4000000); + _spi.frequency(1000000); #define TIME_OUT 50 start_to = t.read_ms() ; - do writeReg(REG_SYNCVALUE1, 0xaa); while (readReg(REG_SYNCVALUE1) != 0xaa && t.read_ms()-start_to < TIME_OUT); + do writeReg(REG_SYNCVALUE1, 0xaa); while (readReg(REG_SYNCVALUE1) != 0xaa);// && t.read_ms()-start_to < TIME_OUT); if (t.read_ms()-start_to >= TIME_OUT) return (false); // Set time out start_to = t.read_ms() ; - do writeReg(REG_SYNCVALUE1, 0x55); while (readReg(REG_SYNCVALUE1) != 0x55 && t.read_ms()-start_to < TIME_OUT); + do writeReg(REG_SYNCVALUE1, 0x55); while (readReg(REG_SYNCVALUE1) != 0x55);// && t.read_ms()-start_to < TIME_OUT); if (t.read_ms()-start_to >= TIME_OUT) return (false); for (uint8_t i = 0; CONFIG[i][0] != 255; i++) writeReg(CONFIG[i][0], CONFIG[i][1]); @@ -140,7 +140,7 @@ // Disable it during initialization so we always start from a known state. encrypt(0); - setHighPower(_isRFM69HW); // called regardless if it's a RFM69W or RFM69HW + //setHighPower(_isRFM69HW); // called regardless if it's a RFM69W or RFM69HW setMode(RF69_MODE_STANDBY); // Set up interrupt handler start_to = t.read_ms() ; @@ -244,8 +244,8 @@ void RFM69::send(uint8_t toAddress, const void* buffer, uint8_t bufferSize, bool requestACK) { writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFB) | RF_PACKET2_RXRESTART); // avoid RX deadlocks - uint32_t now = t.read_ms(); - while (!canSend() && t.read_ms() - now < RF69_CSMA_LIMIT_MS) receiveDone(); + //uint32_t now = t.read_ms(); + //while (!canSend() && t.read_ms() - now < RF69_CSMA_LIMIT_MS) receiveDone(); sendFrame(toAddress, buffer, bufferSize, requestACK, false); } @@ -301,7 +301,7 @@ { setMode(RF69_MODE_STANDBY); // turn off receiver to prevent reception while filling fifo while ((readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // wait for ModeReady - writeReg(REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_00); // DIO0 is "Packet Sent" + //writeReg(REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_00); // DIO0 is "Packet Sent" if (bufferSize > RF69_MAX_DATA_LEN) bufferSize = RF69_MAX_DATA_LEN; // control byte @@ -325,8 +325,8 @@ // no need to wait for transmit mode to be ready since its handled by the radio setMode(RF69_MODE_TX); uint32_t txStart = t.read_ms(); - while (_interrupt == 0 && t.read_ms() - txStart < RF69_TX_LIMIT_MS); // wait for DIO0 to turn HIGH signalling transmission finish - //while (readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PACKETSENT == 0x00); // wait for ModeReady + //while (_interrupt == 0 && t.read_ms() - txStart < RF69_TX_LIMIT_MS); // wait for DIO0 to turn HIGH signalling transmission finish + while ((readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PACKETSENT) == 0x00); // wait for ModeReady setMode(RF69_MODE_STANDBY); } // ON = disable filtering to capture all frames on network