diff --git a/README.md b/README.md index e0be4da..6ad8139 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,4 @@ Experimental project to drive an RFM69 radio module with plain avr-libc. -Initializes the module and reads out register RegOpMode (0x01). -That's all for now. +This is work in progress. diff --git a/avrrfm.c b/avrrfm.c index 3b5d0c4..39f210a 100644 --- a/avrrfm.c +++ b/avrrfm.c @@ -89,7 +89,8 @@ initSPI(); initI2C(); initRadioInt(); - initRadio(); + + initRadio(868600); // enable global interrupts sei(); diff --git a/rfm69.c b/rfm69.c index 01cb472..310ab5b 100644 --- a/rfm69.c +++ b/rfm69.c @@ -49,14 +49,24 @@ return value; } -void initRadio(void) { - // wait a bit after POR +void initRadio(uint32_t kHz) { + // wait a bit after power on _delay_ms(10); // pull reset LOW to turn on the module PORT_RFM &= ~(1 << PIN_RRST); - _delay_ms(5); + _delay_ms(5); + + setFreq(kHz); +} + +void setFreq(uint32_t kHz) { + kHz = kHz * 1000 / 61; + + regWrite(FRF_MSB, kHz >> 16); + regWrite(FRF_MID, kHz >> 8); + regWrite(FRF_LSB, kHz >> 0); } void doStuff(void) { diff --git a/rfm69.h b/rfm69.h index 9570d7a..6738cff 100644 --- a/rfm69.h +++ b/rfm69.h @@ -15,15 +15,26 @@ #include "spi.h" #include "usart.h" -#define FIFO 0x00 -#define OP_MODE 0x01 +#define FIFO 0x00 +#define OP_MODE 0x01 -#define NODE_ADDR 0x39 +#define FRF_MSB 0x07 +#define FRF_MID 0x08 +#define FRF_LSB 0x09 + +#define NODE_ADDR 0x39 /** - * Initializes the radio module. + * Initializes the radio module with the given carrier frequency in kilohertz. */ -void initRadio(void); +void initRadio(uint32_t kHz); + +/** + * Sets the carrier frequency in kilohertz. + * + * @param kHz + */ +void setFreq(uint32_t kHz); /** * Do super useful stuff.