Library for RF transceiver RFM12 with PIC MCUs written in Pascal [130161-I]
The modul RFM12 from HopeRF is a cheap transceiver, which operates in the 433 Mhz and 868 Mhz frequency band. Base of my implementation is the C-code of HopeRF, which is published in the attached PDF file.
The modul RFM12 from HopeRF is a cheap transceiver, which operates in the 433 Mhz and 868 Mhz frequency band. Base of my implementation is the C-code of HopeRF, which is published in the attached PDF file.
As test platform for the transmitter, I use a PIC-Ready-Kit from MikroElektronika, equiped with a PIC18F4620 running at 10 Mhz. The receiver has a PIC18F14K22 running as well with 10 Mhz.
The software does not use specific MCU resources like timer, interrupts and SPI-hardware, it polls the RFM12 pins and even the SPI signals are softmade. (So there is some room for improvements.) Transmission speed is 4.800 Baud.
The implementation has been done in 3 steps:
1. Adaptation of the HopeRF example for MikroElektronica C In the folder 1_Adaptation_of_HopeCode_C you will find projects for TX and RX. The programs can be compiled with the demo version of ME C.
2. Translation of that code to ME Pascal Pro The above software has been tranlated to ME Pascal. The projects for this step are stored in the folder: 2_Translation_to_Pascal.
3. Implementation of the RFM12-lib In the final step, I have put the RFM12 routines in a lib, have defined a simple message format with variable message length and exchanged the checksum method by a CRC16 algorithm. The TX/RX projects of this step are stored in folder: 3_Lib_RFM12_Pascal.
Experience: The connection between TX and RX works very well. With the highest power of tranmitter and maximum gain of receiver (as used for RFM12 parameters). During the test, the tranmitter was located in my (circuit) cellar and I could receive the errorfree signal in my house up to the second floor and in my whole garden, 20 meters away from the house. Because this is sufficient for my projects, I did no further tests.
More information about the RF modules from HopeRF: http://www.hoperf.com/rf_fsk/fsk/
Microchip has with MRF49XA a quite similar product: http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en541404
This software is the base for another project. Primarily it should be used for the integration of remote sensors into my home control systems. But my grandsons have convinced me, that a remote control for their railway toy is much more important. So I have started to develop that first.
Note of Feb. 2013:
Because the developed protocol is not code transparent, there might be in some cases a problem with control bytes, which are included in the payload.
In the PDF document Note_Feb_2013.zip you will find a short description, how to solve this problem by using Hamming en/decoding. In the next release, the author plans to include these functions.
=========== Release 2.0 is ready ===============
The following improvements have been implemented:
Using the SPI-unit of the MCU
Increase the MCU clock from 10 to 40 Mhz
SPI-unit runs with Fosz/64 ~ 600 khz
Fosz/16 ~ 2.4 Mhz has been tested
Messages are Hamming coded in order to reach code transparency.
Each byte is splitted into halfbytes and coded according to Hamming.
This cuts the effective transfer speed to half of RFM12 speed.
Hamming code is used for error detection only, the possible
correction of 1-bit-errors is not implemented.
RFM speeds of 4800, 9600, 19200 Baud have been successfully tested,
but the higher speeds reduce the transmission range.
Recommendation: RFM12 with 4800, means 2400 net speed.
Remarks:
The software still works in polling mode, which blocks the MCU
during GetRFMMsg and PutRFMMsg.
Software and sample projects are attached in the file
RFM12_Transceiver_Rel20_Elektor.zip
Used Compiler: MikroElektronika Pascal Pro 6.01
Size of software: ~ 1500 Bytes, OK for Demoversion of Compiler
========= Release 3.0 is ready =========
Release 3.0 of RFMLib:
This version is now interrupt controlled, that means it does not block the MCU
while a message is received or transmitted. The advantages of Release 2.0,
the support of SPI hardware and transparency by using Hamming code is still
included.
Contents:
RFM30.mpas: This is a test program for the Lib. It is organized a multiple
finite state machine, in order to demonstrate the non-blocking
mode. It uses the external Interrupt on PortB.0. The ISR for this
has to be included in your app as well.
Perform a message transmission:
Init the RFM12 by calling InitRFM12 (only once)
Fill the the buffer TXBU according to the protocol
Start transmission by RFMPutStart
Now you can do something else or
Ask the status of transmission by RFMPutReady
If this function replies with 3 then put is done and OK
Perform a message receive:
Init the RFM12 by calling InitRFM12 (only once)
Start receive by RFMGetStart
Now you can do something else or
Ask the status of receive by RFMGetReady
If this function replies with 3 then get is done and OK
Take the message out of buffer RXBU
RFMLib30.mpas: This is the RFM12-Library Release 3.0
In your application, you only have to use:
InitRFM12
RFMPutStart
RFMPutReady
RFMgetStart
RFMgetReady
Remark: A version of this lib for STM32 MCUs written in C is published in this portal
as well.
========= Release 3.0 for ME Basic =========
Helmut Holm, user of ME Basic, has translated the Pascal release 3.0 with a Pascal-to-Basic converter.
Due to the good translation capabilities, the Basic version passed the functional tests as well.
The Basic project is attached.
The a.m. translater has been developed by Dany Ross and is available on Libstock, the code portal of MikroElektronika, under http://www.libstock.com.
Discussion (0 commentaire(s))