1 /* $Id: rfm12.c,v 1.1 2010/07/11 09:09:26 simimeie Exp $
2 * Functions for communicating with the rfm12(b) module
8 /* Unfortunately, the manufacturer documentation for chip and module is
9 * almost unreadable crap.
10 * This one is better: http://www.mikrocontroller.net/articles/RFM12
12 /* Note: the signal is inverted, thus pulling this high DEselects the chip */
13 #define spi_ss_hi() { PORTC |= _BV(0); }
14 /* Consequently, this SELECTS the chip */
15 #define spi_ss_lo() { PORTC &= (uint8_t)~_BV(0); }
17 static void spi_sendbyte(uint8_t v) {
18 /* Start transmission */
20 /* Wait for transmission complete */
21 while ((SPSR & _BV(SPIF)) == 0) {
25 static uint8_t spi_readbyte() {
26 SPDR = 0x00; /* Dummy write */
27 while ((SPSR & _BV(SPIF)) == 0) {
29 /* Return Data Register */
33 void rfm12_init(void) {
34 /* Set MOSI, SCK and SS output, MISO input */
35 DDRB |= _BV(3) | _BV(5);
37 DDRB &= (uint8_t)~_BV(4);
39 /* Enable SPI, Master, set clock rate fck/4.
40 * This works as long as our own clockrate is below 10 MHz - because
41 * 2.5 MHz is the maximum the rfm12b can do. */
42 SPCR |= _BV(SPE) | _BV(MSTR);