diff --git a/README.md b/README.md
index 853fc8a..0723454 100644
--- a/README.md
+++ b/README.md
@@ -5,4 +5,11 @@
This is work in progress. Simple Tx-Rx is working so far.
+To do something really extraordinary, the temperature reading of an MCP9803
+sensor is periodically transmitted to the receiver.
+To save battery power, the controller, radio module and temperature sensor
+are put to power down/sleep mode in between transmissions. The idle current
+is ~57 uA, which is still quite a lot (> 10 uA should be possible), but already
+better than 8 mA :-)
+

diff --git a/avrrfm.c b/avrrfm.c
index f91dbd7..e87c0b9 100644
--- a/avrrfm.c
+++ b/avrrfm.c
@@ -29,7 +29,7 @@
#include "rfm69.h"
#include "mcp9808.h"
-#define MEASURE_INTS 4
+#define MEASURE_INTS 1
/* 1 int = 8 seconds */
static volatile uint8_t ints = 0;
@@ -52,7 +52,7 @@
// set SDA and SCL as output pin
// DDR_I2C |= (1 << PIN_SCL);
// DDR_I2C |= (1 << PIN_SDA);
-
+
// set radio CS and RST pin as output pin
DDR_RFM |= (1 << PIN_RCS);
DDR_RFM |= (1 << PIN_RRST);
@@ -150,7 +150,7 @@
uint16_t raw = 0;
raw |= payload[0] << 8;
raw |= payload[1];
-
+
int16_t tempx10 = convertTemp(raw);
div_t temp = div(tempx10, 10);
static char buf[16];
@@ -188,7 +188,7 @@
sleepRadio();
disableSPI();
}
-
+
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_mode();
} else {
diff --git a/nbproject/Makefile-Custom.mk b/nbproject/Makefile-Custom.mk
index e697dc0..3ff2c88 100644
--- a/nbproject/Makefile-Custom.mk
+++ b/nbproject/Makefile-Custom.mk
@@ -36,9 +36,9 @@
# Object Files
OBJECTFILES= \
${OBJECTDIR}/_ext/48b9ad18/avrrfm.o \
+ ${OBJECTDIR}/_ext/48b9ad18/mcp9808.o \
${OBJECTDIR}/_ext/48b9ad18/rfm69.o \
- ${OBJECTDIR}/_ext/48b9ad18/spi.o \
- ${OBJECTDIR}/mcp9808.o
+ ${OBJECTDIR}/_ext/48b9ad18/spi.o
# C Compiler Flags
@@ -69,6 +69,10 @@
${MKDIR} -p ${OBJECTDIR}/_ext/48b9ad18
$(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=16000000UL -D__AVR_ATmega328P__ -D__flash=volatile -I. -std=c99 -o ${OBJECTDIR}/_ext/48b9ad18/avrrfm.o /home/dode/dev/avrrfm/avrrfm.c
+${OBJECTDIR}/_ext/48b9ad18/mcp9808.o: /home/dode/dev/avrrfm/mcp9808.c
+ ${MKDIR} -p ${OBJECTDIR}/_ext/48b9ad18
+ $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=16000000UL -D__AVR_ATmega328P__ -D__flash=volatile -I. -o ${OBJECTDIR}/_ext/48b9ad18/mcp9808.o /home/dode/dev/avrrfm/mcp9808.c
+
${OBJECTDIR}/_ext/48b9ad18/rfm69.o: /home/dode/dev/avrrfm/rfm69.c
${MKDIR} -p ${OBJECTDIR}/_ext/48b9ad18
$(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=16000000UL -D__AVR_ATmega328P__ -D__flash=volatile -I. -o ${OBJECTDIR}/_ext/48b9ad18/rfm69.o /home/dode/dev/avrrfm/rfm69.c
@@ -77,10 +81,6 @@
${MKDIR} -p ${OBJECTDIR}/_ext/48b9ad18
$(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=16000000UL -D__AVR_ATmega328P__ -D__flash=volatile -I. -std=c99 -o ${OBJECTDIR}/_ext/48b9ad18/spi.o /home/dode/dev/avrrfm/spi.c
-${OBJECTDIR}/mcp9808.o: mcp9808.c
- ${MKDIR} -p ${OBJECTDIR}
- $(COMPILE.c) -g -DBAUD=38400 -DDRIVER=1 -DF_CPU=16000000UL -D__AVR_ATmega328P__ -D__flash=volatile -I. -o ${OBJECTDIR}/mcp9808.o mcp9808.c
-
# Subprojects
.build-subprojects:
diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml
index 27b240e..1b55900 100644
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -45,16 +45,16 @@
-
+ -
+
+ -
+
-
-
-
- -
-
- -
-
diff --git a/rfm69.c b/rfm69.c
index 1ab828b..58ec333 100644
--- a/rfm69.c
+++ b/rfm69.c
@@ -86,20 +86,25 @@
printString("Version: ");
printHex(version);
- // packet mode, FSK modulation, no shaping
+ // packet mode, FSK modulation, no shaping (default)
regWrite(DATA_MOD, 0x00);
// bit rate 9.6 kBit/s
- regWrite(BITRATE_MSB, 0x0d);
- regWrite(BITRATE_LSB, 0x05);
+ // regWrite(BITRATE_MSB, 0x0d);
+ // regWrite(BITRATE_LSB, 0x05);
- // RC calibration, must be done in standby mode (default)
+ // RC calibration, must be done in standby mode (default after power on)
regWrite(OSC1, 0x80);
do { } while (!(regRead(OSC1) & 0x40));
+ // PA level 17 dBm (default 13 dBm)
+ // regWrite(PA_LEVEL, 0x7f);
+
// LNA 200 Ohm, gain AGC (default)
regWrite(LNA, 0x88);
- // reduce gain if transmitter and receiver are close to each other
+ // max gain
+ // regWrite(LNA, 0x89);
+ // reduced gain
// regWrite(LNA, 0x86);
// freq of DC offset canceller and channel filter bandwith (default)
@@ -108,6 +113,10 @@
// RX_BW during AFC (default)
regWrite(AFC_BW, 0x8b);
+ // Preamble size
+ regWrite(PREAMB_MSB, 0x00);
+ regWrite(PREAMB_LSB, 0x0f);
+
// turn off CLKOUT (not needed)
regWrite(DIO_MAP2, 0x07);
@@ -151,7 +160,7 @@
void wakeRadio(void) {
setMode(MODE_STDBY);
- // TODO necessary?
+ // should better wait for ModeReady irq?
_delay_ms(5);
}
diff --git a/rfm69.h b/rfm69.h
index 08cc9c1..1f8ef7d 100644
--- a/rfm69.h
+++ b/rfm69.h
@@ -25,6 +25,7 @@
#define FRF_MID 0x08
#define FRF_LSB 0x09
#define OSC1 0x0a
+#define PA_LEVEL 0x11
#define LNA 0x18
#define RX_BW 0x19
#define AFC_BW 0x20