first preparations for talking to the rfm12 module (note that nothing of
authorsimimeie <simimeie>
Sun, 11 Jul 2010 09:09:26 +0000 (09:09 +0000)
committersimimeie <simimeie>
Sun, 11 Jul 2010 09:09:26 +0000 (09:09 +0000)
use is implemented yet).

rfm12.c [new file with mode: 0644]
rfm12.h [new file with mode: 0644]

diff --git a/rfm12.c b/rfm12.c
new file mode 100644 (file)
index 0000000..01297e4
--- /dev/null
+++ b/rfm12.c
@@ -0,0 +1,43 @@
+/* $Id: rfm12.c,v 1.1 2010/07/11 09:09:26 simimeie Exp $
+ * Functions for communicating with the rfm12(b) module
+ */
+
+#include <avr/io.h>
+#include "rfm12.h"
+
+/* Unfortunately, the manufacturer documentation for chip and module is
+ * almost unreadable crap.
+ * This one is better: http://www.mikrocontroller.net/articles/RFM12
+ */
+/* Note: the signal is inverted, thus pulling this high DEselects the chip */
+#define spi_ss_hi() { PORTC |= _BV(0); }
+/* Consequently, this SELECTS the chip */
+#define spi_ss_lo() { PORTC &= (uint8_t)~_BV(0); }
+
+static void spi_sendbyte(uint8_t v) {
+  /* Start transmission */
+  SPDR = v;
+  /* Wait for transmission complete */
+  while ((SPSR & _BV(SPIF)) == 0) {
+  }
+}
+
+static uint8_t spi_readbyte() {
+  SPDR = 0x00; /* Dummy write */
+  while ((SPSR & _BV(SPIF)) == 0) {
+  }
+  /* Return Data Register */
+  return SPDR;
+}
+
+void rfm12_init(void) {
+  /* Set MOSI, SCK and SS output, MISO input */
+  DDRB |= _BV(3) | _BV(5);
+  DDRC |= _BV(0);
+  DDRB &= (uint8_t)~_BV(4);
+  spi_ss_hi();
+  /* Enable SPI, Master, set clock rate fck/4.
+   * This works as long as our own clockrate is below 10 MHz - because
+   * 2.5 MHz is the maximum the rfm12b can do. */
+  SPCR |= _BV(SPE) | _BV(MSTR);
+}
diff --git a/rfm12.h b/rfm12.h
new file mode 100644 (file)
index 0000000..df96924
--- /dev/null
+++ b/rfm12.h
@@ -0,0 +1,10 @@
+/* $Id: rfm12.h,v 1.1 2010/07/11 09:09:26 simimeie Exp $
+ * Functions for communicating with the rfm12(b) module
+ */
+
+#ifndef __RFM12B_H__
+#define __RFM12B_H__
+
+void rfm12_init(void);
+
+#endif /* __RFM12B_H__ */
This page took 0.046146 seconds and 4 git commands to generate.