Advertisement

RFM12B and AVR — quick start
1

Introduction

The RFM12B tranceiver module has become quite popular recently due
to its low price comparing to other modules on the market. But many
people find it hard to make these tranceivers work (mainly because of buggy
programming guide provided by manufacturer, I guess...). This short article
contains compact and simple code that can be used just to get these modules
running for the first time. It is based on manufacturer's examle code with
slight (but crucial) changes.
2

Schematic

To interface RMF12B modules I used Atmel's ATtiny2313. Schematic is
shown on figure 1. Recommended power supply for the module is 3.8V so I
decided to power both the processor and the module from 3.3V. It can be a
problem with the Mega family as you will need "L" version then. Some people
claim that they run those modules from 5V and everything's fine. The other
solution is splitted power supply (5V for processor and 3.3V for RFM12B)
but resistors are needed on IO pins (5kΩ or so) in this case. Implementing
SPI interface doesn't require strict time delays or clock stability so processor
is running on the 8MHz internal RC oscillator.
3

Transmitter code

Full source code for both the transmitter and the receiver can be found in
1
rfm12b.zip
. Transmitter part contains functions supporting RS232 trans-
mission, but you can omit them as they are not used in the there. First, we
define some macros to keep the program clear.
1
http://loee.jottit.com/rfm12b and avr - quick start
1

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the RFM12B and is the answer not in the manual?

Questions and answers

Summary of Contents for Hope RF RFM12B

  • Page 1 Mega family as you will need ”L” version then. Some people claim that they run those modules from 5V and everything’s fine. The other solution is splitted power supply (5V for processor and 3.3V for RFM12B) but resistors are needed on IO pins (5kΩ or so) in this case. Implementing SPI interface doesn’t require strict time delays or clock stability so processor...
  • Page 2 Figure 1. Circuit schematic /* RFM12B INTERFACE */ #define SCK 7 // SPI clock #define SDO 5 // SPI Data output (RFM12B side) #define SDI 6 // SPI Data input (RFM12B side) #define CS // SPI SS (chip select) #define NIRQ 2...
  • Page 3 unsigned int writeCmd(unsigned int cmd) { unsigned char i; unsigned int recv; recv = 0; LO(SCK); LO(CS); for(i=0; i<16; i++) { if(cmd&0x8000) HI(SDI); else LO(SDI); HI(SCK); recv<<=1; if( PINB&(1<<SDO) ) { recv|=0x0001; LO(SCK); cmd<<=1; HI(CS); return recv; Initialization of radio module was taken from the ”Programming Guide”. All I changed was first command (868MHz band instead of 434MHz).
  • Page 4 thing is to remember to read status register (writeCmd(0x0000)) before each frame (without that line my transmitter was dead). int main() { volatile unsigned int i,j; asm("cli"); for(i=0;i<1000;i++)for(j=0;j<123;j++); portInit(); rfInit(); while(1){ LED_ON(); writeCmd(0x0000); rfSend(0xAA); // PREAMBLE rfSend(0xAA); rfSend(0xAA); rfSend(0x2D); // SYNC rfSend(0xD4);...
  • Page 5 Receiver code Here things get a little bit inconsistent with the ”Programming Guide”. Macros, port initialization and SPI handling in the receiver part is the same as before so I will omit some code. The easiest way to check received data is to send it to the PC.
  • Page 6 RF12B datasheet, page 25, reception can be done either in interrupt mode or polling mode. To choose interrupt mode we need to have FFIT/DCLK pin connected to the processor. Because I haven’t got than pin connected on my PCB I had to implement the polling mode. In this mode I read status register (the same datasheet, page 23) and check first bit (FFIT) in a loop.
  • Page 7: Useful Links

    I haven’t tried any of this possibilities yet, so if you’re interested you can investigate it on your own. Good luck! Useful links Manufacturer’s documentation: - IC datasheet http://www.hoperf.com/pdf/RF12B.pdf - module datasheet http://www.hoperf.com/pdf/RFM12B.pdf - Programming Guide http://www.hoperf.com/pdf/RF12B code.pdf Other links: - http://www.embedds.com/interfacing-rfm12-transceiver-module/ - http://electronics-diy.com/electronic schematic.php?id=725 - http://svn.everythingrobotics.com/strobist/mk1/trunk/arch/pic16f88- boostc/src/ - http://www.mikrocontroller.net/topic/67273...

Table of Contents