diff --git a/avrrfm.c b/avrrfm.c index 2810e40..45db55d 100644 --- a/avrrfm.c +++ b/avrrfm.c @@ -33,15 +33,18 @@ #include "dejavu.h" #include "unifont.h" -#define MEASURE_INTS 4 +#define MEASURE_INTS 1 #define LABEL_OFFSET 10 #define BLACK 0x0000 #define RED 0xf800 #define WHITE 0xffff +#define NODE1 0x24 +#define NODE2 0x42 + #ifndef RECEIVER - #define RECEIVER 1 + #define RECEIVER 0 #endif /* 1 int = 8 seconds */ @@ -144,12 +147,13 @@ } /** - * Reads the temperature from the sensor and transmits it. + * Reads the temperature from the sensor and transmits it with the given + * node address. */ -static void transmitTemp(void) { +static void transmitTemp(uint8_t node) { uint16_t temp = readTSens(); uint8_t payload[] = {(temp >> 8), temp & 0x00ff}; - transmitPayload(payload, sizeof (payload)); + transmitPayload(payload, sizeof (payload), node); // printString("Transmitted\r\n"); } @@ -214,13 +218,13 @@ sei(); printString("Hello Radio!\r\n"); + + uint8_t node = RECEIVER ? NODE1 : NODE2; - initRadio(868600); + initRadio(868600, node); if (RECEIVER) { initDisplay(); - - setFrame(0xffff); - + setFrame(WHITE); // initial rx mode startReceive(); } @@ -237,7 +241,7 @@ enableSPI(); wakeTSens(); wakeRadio(); - transmitTemp(); + transmitTemp(NODE1); sleepTSens(); sleepRadio(); disableSPI(); diff --git a/rfm69.c b/rfm69.c index 658289f..090a798 100644 --- a/rfm69.c +++ b/rfm69.c @@ -74,7 +74,7 @@ // printString("irq\r\n"); } -void initRadio(uint64_t freq) { +void initRadio(uint64_t freq, uint8_t node) { // wait a bit after power on _delay_ms(10); @@ -171,7 +171,7 @@ regWrite(PCK_CFG2, 0x00); // node and broadcast address - regWrite(NODE_ADDR, NODE_ADDRESS); + regWrite(NODE_ADDR, node); regWrite(CAST_ADDR, CAST_ADDRESS); // set TX start condition to "at least one byte in FIFO" @@ -243,14 +243,14 @@ return readPayload(payload, size); } -size_t transmitPayload(uint8_t *payload, size_t size) { +size_t transmitPayload(uint8_t *payload, size_t size, uint8_t node) { // payload + address byte size_t len = min(size, FIFO_SIZE) + 1; spiSel(); transmit(FIFO | 0x80); transmit(len); - transmit(NODE_ADDRESS); + transmit(node); for (size_t i = 0; i < size; i++) { transmit(payload[i]); } diff --git a/rfm69.h b/rfm69.h index 09fba85..67847e4 100644 --- a/rfm69.h +++ b/rfm69.h @@ -75,13 +75,13 @@ #define FIFO_SIZE 64 #define F_STEP 6103515625ULL -#define NODE_ADDRESS 0x42 #define CAST_ADDRESS 0x84 /** - * Initializes the radio module with the given carrier frequency in kilohertz. + * Initializes the radio module with the given carrier frequency in kilohertz + * and node address. */ -void initRadio(uint64_t kHz); +void initRadio(uint64_t freq, uint8_t node); /** * Shuts down the radio. @@ -117,9 +117,9 @@ * Sets the radio in standby mode, puts the payload into the given array * with the given size, and returns the length of the payload. * - * @param payload - * @param size - * @return actual length of the payload + * @param payload buffer for payload + * @param size of payload buffer + * @return payload bytes actually received */ size_t readPayload(uint8_t *payload, size_t size); @@ -128,17 +128,20 @@ * given size, and returns the length of the payload. * * @param payload buffer for payload - * @return bytes actually received + * @param size of payload buffer + * @return payload bytes actually received */ size_t receivePayload(uint8_t *payload, size_t size); /** - * Transmits up to 64 bytes of the given payload. + * Transmits up to 64 bytes of the given payload with the given node address. * * @param payload to be sent - * @return bytes actually sent + * @param size of payload + * @param node address + * @return payload bytes actually sent */ -size_t transmitPayload(uint8_t *payload, size_t size); +size_t transmitPayload(uint8_t *payload, size_t size, uint8_t node); #endif /* RFM69_H */