In a previous post, establishing Radio Frequency (RF)
communication between Anaren Booster Pack modules diverged to focus more on
Passive Infra Red (PIR) motion sensor and how to program MSP430 Launch Pad to
display motion detection status. Instead, this post will focus more on the
programming task, hopefully.
To recap, objective was to establish RF communication
with some payload (a frame of data) to indicate the detection output status of
a motion sensor. Also, there was supply power conflict (+5V versus +3V) between
Texas Instrument micro controller and the sensor. While you can read more on
interfacing motion sensor to the micro controller in here, we will talk about programming the
communication modules in this post and save talk about power supply for a
following post.
Anaren Booter Pack has two boards with Anaren RF chips pre-installed,
plus two microcontrollers pro-flashed with Anaren software stack. “It is all
about the protocol stack” according to Anaren; it is open source and based on
Texas Instruments Simplicity protocol stack. While their documentation is kind
of detailed for almost every important function in the stack, the length of the
code is terrible to say the least.
After spending a week on understanding where/what function
to modify in Anaren protocol stack, I was confessed that there is some price to
pay for their protocol stack and the graphical user interface that they
advertised.
Figure 1 Anaren GUI, note the windows showing RSSi and Temperature |
As you can see above, many options for the RF
chip can be controlled from GUI; almost all the parameters including:
transmit
power ( tx power), transmit frequency, channel, and FCC/ETSI compliance.
Furthermore, you can see actual serial data communicated between the
micro controller and the RF chip, done through SPI. Off course, the GUI
has two
windows to display the received signal strength on each chip and the
temperature of each chip, yes TI has built in functions to measure the
temperature, battery strength,…etc. Actually you will learn in the end
of this
post that TI does a very good job of providing support to their chips,
unlink
Anaren.Now, do not get me wrong!! I have to be thankful for humble
price of their board, nicely labeling it, effort made to document functions in
their stack and providing two versions of their protocol stack: one for Code
Composer Studio and one for IAR workbench for TI MSP430 environment.
Figure 2 Anaren Protocol Stack (IAR Embedded Workbench for MSP430 Environment) |
Lines and lines of code is what you get when you look into
their protocol stack. As you can see above, main components include FCC/ETSI
setting, application layer, protocol layer and the framework layer. The later
is what we need to modify in most cases to make advantage of Anaren protocol
stack. The application layer code, as name implies, is made of the set of
instruction to allow successful communication between the nodes and the hub;
the main topology is Star topology. In addition to data exchange
(data/configuration data), this layer implements a full communication protocol:
adding/removing a node from the network (assigning node ID), network validation,
setting cycle time and radio sleep/wake process. The application layer intended
to facilitate communication between the RF module and the Launch Pad through
SPI protocol (to change settings, to receive sensor data and to listen to
incoming packets received on the RF module). As we just mentioned, to make any
advantage of the protocol stack you must manipulate the framework layer to make
it interface your hardware used, like sensors, batteries, display, …etc.
Yes, you are right, if you do not like it why use it,
probably that is what you are thinking. Let me explain the problems you come to
meet once you try to understand/used Anaren protocol stack:
- IAR workbench for MSP430 environment has a limitation of 2k byte of code; when you try to compile and load a large program like Anaren protocol stack you will get a message “code size exceeds limit for this version”
- Code Composer version of the protocol stack I have not tried but you can figure from feedback that it is not easy to use it
- Protocol Stack has too many layers; it is well organized for someone who wrote it. But if you want to tweak the code to achieve certain programming task it is a nightmare to go through whole stack.
One thing tempts you to think of alternatives to Anaren code
is Texas Instruments resources, starting with code snippet for many modules in
their micro controller to Simplicity protocol stack written by Texas
Instruments. In short, the learning curve for Anaren code is equal to going
through Texas Instruments code available on line and starting to tweak them to
you own desire. Remember Texas Instruments warning about side effects when
combining their code snippet and not making your own program.
On lines of what we mentioned above, you can find here code to run Anaren RF
modules based on the code provided by Texas Instruments for allowing
communication between chip CC2520/CC110L and a TI board, like Launch Pad or
EZ430 board. An interrupt coming on the
SPI pin (pin 1.6) will indicate the RF chip received something, and when you
want to send something you just put it on the SPI pin and let the RF chip send
it. Basically, you will use the RF chip as queue: allow it to transmit anything that it gets on the SPI port and allow it to write to SPI port anything it receives. The author of this code
added a mechanism to check for successful transmission of a packet, an
acknowledgment sent from the receiver on the other side. Obviously, this
approach does not work well when you have a sequence of data to transmit.
According to comments from people using this code, it can be used with more than one
transmitter/receiver talking to the hub node, I can not refute or confirm. I changed the main program in the code above
to make it suit my purpose; turn ON RED LED on one Launch Pad once motion is detected on the other Launch Pad.
Below you will find a video showing how to use code above,
after some modification, to transmit the status of PIR sensor to anther Anaren
RF Module. In the video you will note a booster circuit that we will talk about
in a following post, please stay tuned.