<< Chapter < Page Chapter >> Page >
This first example involves two boards which stay in Rx mode by default. When you press a button on either one, it sends amessage and toggles its green LED; the board which receives the message toggles its red LED. Once this is functional, youwill play with the Rx/Tx frequency.

Running the code

  • Copy the code presented below Alternatively, this code is available in the downloadable source code . Open source_code/iar_v4.11/lab_ezwsn.eww with IAR. The project corresponding to this section is called txrx_simple . .
  • Compile and download the code onto both boards (Ctrl+D) .
  • Switch both boards on (one with the battery unit, the other with the USB slot of your PC); when you press one's button, the other's red LED should toggle.
#include "mrfi.h" #include "radios/family1/mrfi_spi.h"int main(void) {BSP_Init(); P1REN |= 0x04;P1IE |= 0x04; MRFI_Init();MRFI_WakeUp(); MRFI_RxOn();__bis_SR_register(GIE+LPM4_bits); }void MRFI_RxCompleteISR() {P1OUT ^= 0x02; }#pragma vector=PORT1_VECTOR __interrupt void Port_1 (void){ P1IFG&= ~0x04; mrfiPacket_t packet;packet.frame[0]=8+20;MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED); P1OUT ^= 0x01;}
The simplest Tx/Rx example possible

The packet format is:

packet.frame
Length (1B) Source (4B) Destination (4B) Payload (Length-8 bytes long)
packet.rxMetrics
RSSI (1B) CRC (1b) LQI (1b)

A variable of type mrfiPacket_t is a structure containing two parts:

  • packet.frame is the frame to be transmitted. The first byte is the Length of the payload together with source and destination Address. With the current driver implementation, addresses are coded on 4 bytes, and the maximumPayload length is 20 bytes. By default, the CC2500 does not perform address filtering, so in practice we will not care about the values of the address fields.
  • packet.rxMetrics are statistics on the last received packet, i.e. it only makes sense on received packet. The first byte is the Received Signal StrengthIndicator ( RSSI ) at sync word detection. This is the signal level in dBm. The next bit indicates whether the Cyclic Redundancy Check ( CRC ) was successful (by default, the CC2500 is configured to reject packets with unsuccessful CRCcheck, so in practice this field will always be 1). The last 7 bits are the Link Quality Indicator ( LQI ). The LQI gives an estimate of how easily a received signal can be demodulated by accumulating the magnitude of the error between idealconstellations and the received signal over the 64 symbols immediately following the sync word.

Some keys for understanding the code:

  • Line 4 is a function from the drivers (right-click on it, and choose Go to definition of "BSP_Init()" if you want to know) which disables the watchdog, initializes the MCLK at 8MHz, sets LED ports as outputs and thebutton port as input. Note that it does neither enables the internal resistor of the button, nor enables interrupts. This is done on lines 5 and 6.
  • Line 7. MRFI stands for Minimal Radio-Frequency Interface; functions starting with MRFI are used to drive the CC2500 radio chip. MRFI_Init() initializes the 6 wires between the MSP430 and the CC2500, powers-up the CC2500 and configures the CC2500 47 registers and turns on interrupts from the CC2500;
  • Line 8 wakes up the radio, i.e. it turns on the 26MHz crystal attach to it without entering Rx or Tx mode;
  • Line 9 switches the radio to Rx mode; from this line on, it can receive packets, in which case the interrupt function MRFI_RxCompleteISR is called Note that the real interrupt function with the usual #pragma declaration is hidden in the drivers .

Choosing a frequency

The CC2500 can transmit at any frequency on the ISM band 2400.0-2483.5 MHz . The chip divides the 2400.0-2483.5 MHz spectrum into channels separated by a tunable channel spacing . By default, channel spacing is 200kHz; with default configuration, channel 0 is 2433.0Mhz, channel 1 is 2433.2Mhz, and so forth. Thechannel is configured through the CHANNR register of the CC2500.

  • add 1 the following line at the very top of the code. This way, you have access to low level driver functions which enable you to write directly the CC2500 registers: #include "radios/family1/mrfi_spi.h"
  • add the following line right after MRFI_Init(); . You may replace 0x10 by the frequency you have chosen. This programs the CHANNR register of the CC2500. Be aware that values above 0xFC are prohibited because the corresponding frequency is above 2483.5 MHz: mrfiSpiWriteReg(CHANNR,0x10);

When you have reprogrammed both boards, you should be able to communicatewithout interference.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Ezwsn: experimenting with wireless sensor networks using the ez430-rf2500. OpenStax CNX. Apr 26, 2009 Download for free at http://cnx.org/content/col10684/1.10
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Ezwsn: experimenting with wireless sensor networks using the ez430-rf2500' conversation and receive update notifications?

Ask