POL
ENG

RFM70 library in C for STM32

If you just need RFM70 library then you will find it below. If you want to read whole story, then don't stop.



Some while ago, colleague from work was looking for some radio modules to its project. One day he came with those tinny devices. When he brought them to work and said what they can do, I couldn't stop wondering theirs price to feature ratio. Immediately I ordered four of them. I've already knew where I want to use them. I've built remote controller with graphic LCD described here and two analog manipulators from cheap game pad. Receiver was even simpler. Of course, on both side I used those modules. I spent many hours trying to communicate them both. Unfortunately I failed. I couldn't get stable connection, so I also couldn't control my model. Project got label "suspended" because I got some other more important to do. Recently I took him from shelf and return to fiddling with him. This time, after some major modifications, everything went smooth. Now I'm laughing and keep saying that we had to mature to each other, but frankly speaking, the real cause of last failure was microcontroller. in receiver.


In first version I used PIC18F452 microcontroller. I found it appropriate to this function. On a beginning everything went fine. First problem occur when I connect a motor. Receiver multiple times hanged and don't react. After many hours it turned out, that original motor emitted a big noise. When I replaced it with new one, situation calmed down and could go farther. Problem returned when I connected servo. It didn't work properly. It was shaking couldn't never get stable position. Moreover timings from datasheet didn't cover with those got from real experiments. No, it wasn't matter of current consumptions. During development, device was powered from power supply. Add huge capacitance on input and additional small 100nF around microcontroller also didn't helped. Inserting choke on input also didn't bring better effects. Finally it turned out, that this PIC had a problem with booting. Even though I put RC circuit on reset line, that should generate reset impulse. Only when I used button it was able to start. At that time, I wished to dig this project at the bottom of my wardrobe. After a few years I decided to get rid of this humorous PIC and place ATmega32. This time it went real smooth... almost. I wanted to be too clever and I lost two evenings before I figure it out that I initialise registers from Bank1 in wrong order.


Anyone who tried to wrote his own library or simply modified this from internet, probably faced with content of datasheet. RFM70 datasheet. I must confess that after first reading I found it very difficult to understand. Not everything was clear, some parts were complicated. After third time it was much easier and I understood what is happening in device. It contains all necessary info there. Looking for answers for various questions in Internet I realized then almost all found libraries for RFM70 have common base library and they were created by "Copy-Paste" method. When got experience I decided that I will prepare my own, also based on that one, but with fixed bugs. I also prepared three configurations with examples how to use them in transmitter and receiver. I wanted to make it more readable and easier to modify for others.


What has been done:

  • Added functions for three different configurations of transmission
  • Cleaned up a code, corrected formating and comments
  • according to note from datasheet, all writes to configuration register should be POWER_UP or STANDBY_I mode (page 12 W_REGISTER operation description). To put device into this state, CE signal must be driven to 0. In original one it was only during setModeTx and setModeRx. I put it to right places
  • Corrected value in register 0x04 in bank 1 which should be 0xD99E860B instead of 0xB99E860B
  • In code, there was a question about toggling values in register. I checked that. It is unnecessary to do it so I removed that code.
  • Decreased power up timing from 3 seconds to 300 milliseconds

Files to download:




Dodaj komentarz


Wszelkie prawa zastrzeżone. Projekt i wykonanie strony SrcPro.pl