diff --git a/README.md b/README.md index 9428f56..eb7a854 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## About Static avr-libc library providing basic support for RFM95 radio modules. -Other RFM9x radios should work as well, but were not tested yet. +Other RFM9x radios might work as well, but were not tested yet. This is work in progress. Simple Tx-Rx with response in FSK mode works so far. @@ -23,29 +23,7 @@ ## Range -Setting `RegPaLevel` to `0x5f`, which gives +13 dBm with `PA1`, indoor range is -very good and in an actual "field" test, packet reception was still reliable -with an RSSI of about -90 dBm at about 2.2 km distance - with simple wire -antennas. What would be the range with +20 dBm and decent antennas? - -![FieldTest3](https://github.com/user-attachments/assets/f2289f8e-1f81-4b85-9146-07c2ce1bb563) - -## Susceptibility to Temperature Changes* - -*This originates from RFM69 radios, if it applies also to RFM9x is yet to be tested. - -With the default frequency deviation of 5 kHz and receiver bandwidth of -10.4 kHz, packet transmission is very unreliable and fails completely for me -when the temperature of the transmitter is below 10°C and above 40°C, while -the receiver temperature is at 20°C. The receiver does not seem to be prone to -temperature changes. -Increasing frequency deviation to 10 kHz and receiver bandwidth to 20.8 kHz, -temperature susceptibility is eliminated; when testing with transmitter -temperature from -20°C to 50°C, packet transmission is perfectly reliable. - -Frequency Deviation = 10 kHz (transmitter) -`RegFdevMsb` = `0x00` -`RegFdevLsb` = `0xa4` - -Receiver Bandwidth = 20.8 kHz -`RegRxBw` = `0x54` +Setting `RegPaConfig` to `0xff`, which gives +17 dBm with `PA_BOOST`, indoor +range is very good and in an actual "field" test, packet reception was still +reliable with an RSSI of about -125 dBm at almost 2.7 km distance - with simple +wire antennas. What would be the range with +20 dBm and decent antennas? diff --git a/librfm.c b/librfm.c index 2804c8e..eec770c 100644 --- a/librfm.c +++ b/librfm.c @@ -63,12 +63,14 @@ if (enable) { // get "Timeout" on DIO4 regWrite(DIO_MAP2, (regRead(DIO_MAP2) | 0x80) & ~0x40); - // both sum up to about 100 ms + // TODO calculate - seems to be about 50, 75, 100ms regWrite(RX_TO_RSSI, 0x1f); - regWrite(RX_TO_PREA, 0x1f); + regWrite(RX_TO_PREA, 0x2f); + regWrite(RX_TO_SYNC, 0x3f); } else { regWrite(RX_TO_RSSI, 0x00); regWrite(RX_TO_PREA, 0x00); + regWrite(RX_TO_SYNC, 0x0f); } } @@ -96,9 +98,7 @@ // regWrite(BITRATE_MSB, 0x0d); // regWrite(BITRATE_LSB, 0x05); - // frequency deviation (default 5 kHz) - increasing to 10 kHz - // completely removes susceptibility to temperature changes - // RX_BW must be increased accordingly + // frequency deviation 10 kHz (default 5 kHz) regWrite(FDEV_MSB, 0x00); regWrite(FDEV_LSB, 0xa4); @@ -109,7 +109,7 @@ regWrite(FRF_LSB, frf >> 0); // PA level +17 dBm with PA_BOOST pin (Pmax default/not relevant) - regWrite(PA_CONFIG, 0xcf); + regWrite(PA_CONFIG, 0xff); // LNA highest gain, no current adjustment regWrite(LNA, 0x20); @@ -117,8 +117,8 @@ // AgcAutoOn, receiver trigger event PreambleDetect regWrite(RX_CONFIG, 0x0e); - // no RSSI offset, 8 samples used - regWrite(RSSI_CONFIG, 0x02); + // no RSSI offset, 32 samples used + regWrite(RSSI_CONFIG, 0x04); // 10 dB threshold for interferer detection regWrite(RSSI_COLLIS, 0x0a); @@ -126,9 +126,7 @@ // RSSI threshold (POR 0xff) regWrite(RSSI_THRESH, 0x94); - // channel filter bandwith (default 10.4 kHz) - // increasing to 20.8 kHz in connection with setting FDEV_*SB to 10 kHz - // completely removes susceptibility to temperature changes + // channel filter bandwith 20.8 kHz (default 10.4 kHz) regWrite(RX_BW, 0x14); // RX_BW during AFC @@ -145,7 +143,7 @@ regWrite(PREA_MSB, 0x00); regWrite(PREA_LSB, 0x03); - // AutoRestartRxMode off, PreamblePolarity 0xaa, SyncOn on, + // AutoRestartRxMode off, PreamblePolarity 0xaa, SyncOn, // FifoFillCondition if SyncAddress, SyncSize + 1 = 4 bytes regWrite(SYNC_CONFIG, 0x13); @@ -211,10 +209,12 @@ } int8_t rfmGetOutputPower(void) { - return (regRead(PA_CONFIG) & 0x1f) - PA_OFF; + return (regRead(PA_CONFIG) & 0x0f) + PA_OFF; } -void rfmStartReceive(void) { +void rfmStartReceive(bool timeout) { + timeoutEnable(timeout); + // get "PayloadReady" on DIO0 regWrite(DIO_MAP1, regRead(DIO_MAP1) & ~0xc0); @@ -253,8 +253,7 @@ } size_t rfmReceivePayload(uint8_t *payload, size_t size, bool timeout) { - timeoutEnable(timeout); - rfmStartReceive(); + rfmStartReceive(timeout); // wait until "PayloadReady" or "Timeout" do {} while (!(irqFlags2 & (1 << 2)) && !(irqFlags1 & (1 << 2))); diff --git a/librfm.h b/librfm.h index afe6d98..625e333 100644 --- a/librfm.h +++ b/librfm.h @@ -174,9 +174,12 @@ int8_t rfmGetOutputPower(void); /** - * Sets the radio to receive mode and maps "PayloadReady" to DIO0. + * Sets the radio to receive mode and maps "PayloadReady" to DIO0 and enables + * or disables timeout. + * + * @param timeout enable timeout */ -void rfmStartReceive(void); +void rfmStartReceive(bool timeout); /** * Returns true if a "PayloadReady" interrupt arrived and clears the @@ -198,8 +201,8 @@ /** * Waits for "PayloadReady", puts the payload into the given array with the - * given size, and returns the length of the payload, or 0 if a timeout - * occurred. + * given size, enables or disables timeout, and returns the length of the + * payload, or 0 if a timeout occurred. * * @param payload buffer for payload * @param size of payload buffer diff --git a/nbproject/Makefile-Custom.mk b/nbproject/Makefile-Custom.mk index a9a3378..0b4c468 100644 --- a/nbproject/Makefile-Custom.mk +++ b/nbproject/Makefile-Custom.mk @@ -28,14 +28,14 @@ CND_BUILDDIR=build # Include project Makefile -include /home/dode/dev/librfm/Makefile +include /home/dode/dev/librfm95/Makefile # Object Directory OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM} # Object Files OBJECTFILES= \ - ${OBJECTDIR}/_ext/5ac08470/librfm.o + ${OBJECTDIR}/_ext/acb12f8c/librfm.o # C Compiler Flags @@ -56,15 +56,15 @@ # Build Targets .build-conf: ${BUILD_SUBPROJECTS} - "${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librfm + "${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librfm95 -${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librfm: ${OBJECTFILES} +${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librfm95: ${OBJECTFILES} ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} - ${LINK.c} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librfm ${OBJECTFILES} ${LDLIBSOPTIONS} + ${LINK.c} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librfm95 ${OBJECTFILES} ${LDLIBSOPTIONS} -${OBJECTDIR}/_ext/5ac08470/librfm.o: /home/dode/dev/librfm/librfm.c - ${MKDIR} -p ${OBJECTDIR}/_ext/5ac08470 - $(COMPILE.c) -g -o ${OBJECTDIR}/_ext/5ac08470/librfm.o /home/dode/dev/librfm/librfm.c +${OBJECTDIR}/_ext/acb12f8c/librfm.o: /home/dode/dev/librfm95/librfm.c + ${MKDIR} -p ${OBJECTDIR}/_ext/acb12f8c + $(COMPILE.c) -g -o ${OBJECTDIR}/_ext/acb12f8c/librfm.o /home/dode/dev/librfm95/librfm.c # Subprojects .build-subprojects: diff --git a/nbproject/Makefile-impl.mk b/nbproject/Makefile-impl.mk index 99db176..644c796 100644 --- a/nbproject/Makefile-impl.mk +++ b/nbproject/Makefile-impl.mk @@ -24,7 +24,7 @@ # Project Name -PROJECTNAME=librfm +PROJECTNAME=librfm95 # Active Configuration DEFAULTCONF=Custom diff --git a/nbproject/Makefile-variables.mk b/nbproject/Makefile-variables.mk index b2721e4..61ca9b8 100644 --- a/nbproject/Makefile-variables.mk +++ b/nbproject/Makefile-variables.mk @@ -9,11 +9,11 @@ # Custom configuration CND_PLATFORM_Custom=AVR-Linux CND_ARTIFACT_DIR_Custom=dist/Custom/AVR-Linux -CND_ARTIFACT_NAME_Custom=librfm -CND_ARTIFACT_PATH_Custom=dist/Custom/AVR-Linux/librfm +CND_ARTIFACT_NAME_Custom=librfm95 +CND_ARTIFACT_PATH_Custom=dist/Custom/AVR-Linux/librfm95 CND_PACKAGE_DIR_Custom=dist/Custom/AVR-Linux/package -CND_PACKAGE_NAME_Custom=librfm.tar -CND_PACKAGE_PATH_Custom=dist/Custom/AVR-Linux/package/librfm.tar +CND_PACKAGE_NAME_Custom=librfm95.tar +CND_PACKAGE_PATH_Custom=dist/Custom/AVR-Linux/package/librfm95.tar # # include compiler specific variables # diff --git a/nbproject/Package-Custom.bash b/nbproject/Package-Custom.bash index 3a6cf36..9a6358a 100644 --- a/nbproject/Package-Custom.bash +++ b/nbproject/Package-Custom.bash @@ -13,9 +13,9 @@ CND_DLIB_EXT=so NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging TMPDIRNAME=tmp-packaging -OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librfm -OUTPUT_BASENAME=librfm -PACKAGE_TOP_DIR=librfm/ +OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librfm95 +OUTPUT_BASENAME=librfm95 +PACKAGE_TOP_DIR=librfm95/ # Functions function checkReturnCode @@ -60,15 +60,15 @@ # Copy files and create directories and links cd "${TOP}" -makeDirectory "${NBTMPDIR}/librfm/bin" +makeDirectory "${NBTMPDIR}/librfm95/bin" copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 # Generate tar file cd "${TOP}" -rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/librfm.tar +rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/librfm95.tar cd ${NBTMPDIR} -tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/librfm.tar * +tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/librfm95.tar * checkReturnCode # Cleanup diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 18bdf72..92d7847 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -1,22 +1,22 @@ - + librfm.c - /home/dode/dev/librfm/Makefile - /home/dode/dev/librfm/nbproject/private/launcher.properties + /home/dode/dev/librfm95/Makefile + /home/dode/dev/librfm95/nbproject/private/launcher.properties ^(nbproject)$ - /home/dode/dev/librfm + /home/dode/dev/librfm95 - /home/dode/dev/librfm/Makefile + /home/dode/dev/librfm95/Makefile @@ -26,7 +26,7 @@ - + diff --git a/nbproject/project.xml b/nbproject/project.xml index 969067c..f3a8b32 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -3,14 +3,14 @@ org.netbeans.modules.cnd.makeproject - librfm + librfm95 c h UTF-8 - /home/dode/dev/librfm + /home/dode/dev/librfm95