RMF12B interfaced to an Atmel AVR ATmega88 running Bascom code
July 22, 2008
The first project I want to share was used as a learning tool to get to know how to use the HopeRF RFM12 / RFM12B wireless transceiver modules. This post will also be a learning tool for writing a post. So please excuse any short comings of this first attempt at blogging.
This picture shows the RFM12 with a quarter for scale.

And the connector side looks like this.

The RFM12 modules are small, low cost(about $8.00 US), short range (150 – 200M claimed), data transceivers. They use the Serial Peripheral Interface (SPI) bus to talk to a micro controller. I’ve interfaced them to an Atmel ATmega88 micro controller programed with the MCS Bascom-avr compiler. My test boards are very simple, consisting of little more then the micro controller and an RFM12 module. Two of these test boards are needed for this project. I will not be showing complete schematics, I’m assuming that the reader can get the micro controller up and running and talking to a PC over a serial line. The challenging part for me was writing the code and its that part that I want to share. There are dozens of avr boards out there that this work could be applied to.
Here is a picture of one of my test boards.

The Hardware:
The pin spacing on the RF modules are 2mm on center, not very convenient for connecting to the prototype boards I was using. I was able to modify a connector from an old printer to adapt the modules to my boards. You can see this in the picture above. There may be adapter boards or ribbon connectors that would do as well or better. Or you could solder to the pins directly, but if the part failed that could end up being a big headache. In the polling mode of operation that is being used here only four wires are needed. I am using one additional connection, the nRES signal, which is optional. It allows for the software to reset the RFM12 modules. Now that the code is working well there is little need for the nRES signal. Here is a link to a schematic showing the RFM12B connections. Also the nSEL and nRES signals can be reassigned to any free pins in your design. Just remember to change the alias lines in the code to reflect those changes. The design uses the hardware SPI so those three pin assignments are fixed. One more thing about the hardware to note is that I’m using a boot loader to program the AVR controller not a In System Programmer (ISP). If you are using an ISP it will be connected to the same pins as the RFM12 module so it might be necessary to add jumpers to isolate the module during programming.
The Software:
The software is written in MCS electronics BASCOM-AVR compiler. It was written as a test program to get the transceivers up and running. This code is not meant to be a complete RF serial link. It is for testing and evaluating the RFM12 modules only. However with the addition of error detection and correction, I believe a reliable RF link could be relized. In future project here at TechnoFun.org I well be implementing some type of more complete serial protocol using these devices. Here is a link to the Bascom RFM12 code. Frequency can be set by changing the “const Fc = 435.00″ line of the code. And the Payload size (no. of data bytes transmitted) can be changed with the “const Payload_Size = 32″ line. Once you get the code up and running typing any keys followed by the <enter> key will Transmit that data. Pressing the <esc> key in your terminal program will put the uC in command mode.
Commands:
- Type any text, up to the Payload length, followed by <enter> to transmit data.
- <esc> Enter command mode.
- <c> Input a HEX command WORD value to send to RFM12. For example enter: c0e0 <enter> will set the ouput CLK to 10MHZ.
- <e> Toggle Echo. Useful for testing the range of a set of modules. Setup one module to echo and the other to Transmit a beacon. The code will not allow both echo and beacon to be on at the same time.
- <b> Toggle the Beacon. Transmit a test signal continuously and check for a reply.
- <u> Upload a new program to the uC. Only works if you are using a bootloader.
Good Luck and if you have any question please feel free to comment.
Schematic
Example 1 Source Code
June 28,2010 UPDATE:
I have received several emails from people who have had trouble running the above two examples of RFM12 code. So here are three more examples that are much simpler to use and debug, I hope. Try these first then if your hardware is working you can try the examples above if you like.
Simple Rx 101 using polling.bas
The last example uses interrupts to get the Rx data. For this example connect nIRQ from the RFM12 to INT0 of your AVR.
Simple Rx 101 using interrupts.bas
Data Sheets:
RF12 chip data sheet - This has the most details about the device.
RFM12 Module data sheet
Other Useful Links:
Good info about using the RFM12 modules by Stephen Eaton. Many Thanks to Stephen for his RFM12 info.

on February 4, 2010 at 3:34 pm
Permalink
@Admin
Nice tutorial, I recently used YS1020 transceiver for my project because of its wide range and simplicity serial communication (TTL RX TX). But it run on 5V environment. And now, because i want to develop a handheld application which is run on 3,3V max, I want to use RFM12, because it has a great transfer rate, n also quite easy to communicate with it.
Great Post Dave.. I already bookmark this site ^^
@Aan…
Konfigurasi ATmega88 dan ATMega8535 memiliki beberapa perbedaan konfigurasi…
Lebih tepatnya lagi, ATMega88 merupakan versi turunan dari ATMega8 karena Atmega8 sudah obsolete.
Supaya lebih mudah dalam pemahaman akan saya jelaskan sedikit migrasi dari ATmega8 ke ATMega88. Ada beberapa perubahan register pada ATMega8 – ATMega88. Sebagai contoh,
TCCR0 ke TCCR0B
TCCR2 ke TCCR2B
OCR20 ke OCR0A
TIFR ke TIFR0 (OCF0 ke OCF0A ) etc..
Untuk lebih lengkapnya lagi dapat dirujuk pada application note Atmel
http://www.atmel.com/dyn/resources/prod_documents/doc2553.pdf
Jika Anda ingin mengembangkan dengan ATMega8535, maka perlu dilakukan beberapa penyesuaian pada alamat vector dan register sesuai yang Anda butuhkan. Silahkan merujuk pada datasheet.
Selamat Berjuang ^^
on August 10, 2010 at 1:00 pm
Permalink
Thank you for the Code, the best i found in the whole Net.
Its very usefull
on September 2, 2010 at 3:48 am
Permalink
thank you for the code *bas*
on September 2, 2010 at 3:53 am
Permalink
ashkan doorandish: thank you