diff --git a/.gitignore b/.gitignore index ccb819d..50d898c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /nbproject/private/ -/avrtft.elf -/avrtft.hex -/avrtft.lst +/avrrfm.elf +/avrrfm.hex +/avrrfm.lst diff --git a/README.md b/README.md index 58d54f6..e0be4da 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # AVRRFM -Experimental to drive an RFM69 radio module with plain avr-libc. - -Initial commit. +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. \ No newline at end of file +That's all for now. diff --git a/avrrfm.c b/avrrfm.c index 8158798..3b5d0c4 100644 --- a/avrrfm.c +++ b/avrrfm.c @@ -94,6 +94,8 @@ // enable global interrupts sei(); + doStuff(); + while (true) { if (int0) { int0 = false; diff --git a/rfm69.c b/rfm69.c index e3da944..01cb472 100644 --- a/rfm69.c +++ b/rfm69.c @@ -1,5 +1,5 @@ /* - * File: rfm69.h + * File: rfm69.c * Author: torsten.roemer@luniks.net * * Created on 28. Januar 2025, 19:57 @@ -7,24 +7,65 @@ #include "rfm69.h" +/** + * Selects the radio to talk to via SPI. + */ +static void spiSel(void) { + PORT_RFM &= ~(1 << PIN_RCS); +} + +/** + * Deselects the radio to talk to via SPI. + */ +static void spiDes(void) { + PORT_RFM |= (1 << PIN_RCS); +} + +/** + * Writes the given value to the given register. + * + * @param reg + * @param value + */ +static void regWrite(uint8_t reg, uint8_t value) { + spiSel(); + transmit(reg | 0x80); + transmit(value); + spiDes(); +} + +/** + * Reads and returns the value of the given register. + * + * @param reg + * @return value + */ +static uint8_t regRead(uint8_t reg) { + spiSel(); + transmit(reg); + uint8_t value = transmit(0x00); + spiDes(); + + return value; +} + void initRadio(void) { // wait a bit after POR _delay_ms(10); - // pull reset low to turn on the module + // pull reset LOW to turn on the module PORT_RFM &= ~(1 << PIN_RRST); - _delay_ms(5); + _delay_ms(5); +} + +void doStuff(void) { + uint8_t opMode = regRead(OP_MODE); + printString("OpMode: "); + printByte(opMode); - /* - radioSel(); - transmit(0x39 | 0x80); - transmit(0xaa); - radioDes(); - */ - radioSel(); - transmit(0x01); - uint8_t reg = transmit(0x00); - radioDes(); - printByte(reg); -} \ No newline at end of file + regWrite(NODE_ADDR, 0xaa); + uint8_t nodeAddr = regRead(NODE_ADDR); + printString("NodeAddr: "); + printByte(nodeAddr); +} \ No newline at end of file diff --git a/rfm69.h b/rfm69.h index 624650d..9570d7a 100644 --- a/rfm69.h +++ b/rfm69.h @@ -15,10 +15,20 @@ #include "spi.h" #include "usart.h" +#define FIFO 0x00 +#define OP_MODE 0x01 + +#define NODE_ADDR 0x39 + /** * Initializes the radio module. */ void initRadio(void); +/** + * Do super useful stuff. + */ +void doStuff(void); + #endif /* RFM69_H */ diff --git a/spi.c b/spi.c index ca1581c..65d43ac 100644 --- a/spi.c +++ b/spi.c @@ -18,17 +18,9 @@ SPSR &= ~(1 << SPI2X); } -void radioSel(void) { - PORT_RFM &= ~(1 << PIN_RCS); -} - -void radioDes(void) { - PORT_RFM |= (1 << PIN_RCS); -} - uint8_t transmit(uint8_t data) { SPDR = data; loop_until_bit_is_set(SPSR, SPIF); return SPDR; -} \ No newline at end of file +} diff --git a/spi.h b/spi.h index bee2638..e9c3f66 100644 --- a/spi.h +++ b/spi.h @@ -23,16 +23,6 @@ void spiFast(void); /** - * Selects the radio to talk to via SPI. - */ -void radioSel(void); - -/** - * Deselects the display to talk to via SPI. - */ -void radioDes(void); - -/** * Transmits the given byte and returns the byte reveived at the same time. * @param data byte to be written * @return byte read while writing