<< Chapter < Page Chapter >> Page >
The CC2500 can easily change its operating frequency, through the use of channels. For each of these channels, theCC2500 can sense the level of electro-magnetic noise, in dBm. The goal of this section is to build a spectrum analyzerby continuously plotting noise vs. frequency. We therefore use a Python script running on the host computer.
For this section, you will need to have installed all the software. If not, please follow the Installation Instructions .

Running the code

  • Copy-paste the code presented below into IAR 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_noise . , and program a single board; close IAR.
  • Copy-paste the python code below into a new file called txrx_noise.py in some directory on your computer Alternatively, this file is already present in the downloadable source code , in the directory source_code/c_files/ . .
  • Connect your USB programmer board to the host computer, and find the COM x port it is connected to. Use PuTTY to read from that x port; you should see a continuous series of 200 numbers appearing.
  • Start an X server onto the host computer using Xlaunch you have installed on your computer.
  • Start Cygwin and go into the folder containing ./txrx_noise.py using command cd path to your folder In cygwin, your Windows drive C:\ is called /cygdrive/c . Also, use forward slashes. If your folder is located at C:\Users\Thomas\Desktop\source_code , in Cygwin, type cd /c/cygdrive/Users/Thomas/Desktop/source_code . .
  • type export DISPLAY=127.0.0.1:0.0
  • type cat /dev/com x . You should see the same content appearing as when using PuTTY. If not, read the COM x port with PuTTY and try again.
  • type cat /dev/com x | ./txrx_noise.py A window appears which looks like the one depicted below.
#include "mrfi.h" #include "radios/family1/mrfi_spi.h"void print_rssi(int8_t rssi) {char output[] = {" 000 "};if (rssi<0) {output[0]='-';rssi=-rssi;}output[1] = '0'+((rssi/100)%10);output[2] = '0'+((rssi/10)%10);output[3] = '0'+ (rssi%10);TXString(output, (sizeof output)-1); }int main(void) {int8_t rssi; uint8_t channel;BSP_Init(); MRFI_Init();P3SEL |= 0x30; UCA0CTL1 = UCSSEL_2;UCA0BR0 = 0x41; UCA0BR1 = 0x3;UCA0MCTL = UCBRS_2; UCA0CTL1&= ~UCSWRST; MRFI_WakeUp();__bis_SR_register(GIE); while(1) {for (channel=0;channel<200;channel++) { MRFI_RxIdle();mrfiSpiWriteReg(CHANNR,channel); MRFI_RxOn();rssi=MRFI_Rssi(); print_rssi(rssi);} TXString("\n",1);} }void MRFI_RxCompleteISR() {}
C code
#!/usr/bin/env python import re, Gnuplot, sysif __name__ == '__main__': print 'display started...'g = Gnuplot.Gnuplot(debug=1) g('set term x11 title "eZWSN sprectum analyzer"')g('set yrange [-110:0]')g('set data style linespoints') g.xlabel('frequency (MHz)')g.ylabel('RSSI (dBm)') char = ''line = '' while 1:char = sys.stdin.read(1) if char == '\n':sline = line.split() data = []for i in range(len(sline)): try:sline[i] = int(sline[i]) except:sline[i] = 0frequency = 2433.0+(0.2*i) data.append([frequency,sline[i]]) g.plot(data)line = '' else:line = line + char
Python code

spectrum_analyzer
Output of the spectrum analyzer in Section 6.2; one transmission is going on on channel 0.

Some keys for understanding the code running on the mote:

  • Line 6. print_rssi() is a function which prints the RSSI value read from the CC2500 onto the serial port which is initialized between lines 18 and 25. TXString() is a function provided in bsp_board.c .
  • Lines 18-25 initialize the serial port, which enable your code to output lines of text using the TXString() function. These lines can then be read using PuTTY.
  • Line 27 instructs the MSP430 to stay in active mode all the time, i.e. not to enter any low power mode.
  • Lines 28-37 is a loop which continuously scans through channels 0-200, recording and outputting the RSSI value. MRFI_Rssi() is a function declared in the drivers.

The python script continuously feeds the GNUplot environment with data received from the standard interface. Note that the content of the right COMx port if pipedto this python script.

Refresh rate of the spectrum analyzer

  • in the code, after line BSP_Init(); , add line P2DIR |= 0x08;
  • in the code, after line TXString("\n",1); , add line P2DIR ^= 0x08; . This toggles extension port P6 every time the screen gets refreshed.
  • using the oscilloscope, measure on extension port P6 the refresh rate of the frequency analyzer. Make sure to refresh rate is around 1.1s.
  • move line P2DIR ^= 0x08; right after line print_rssi(rssi); . You now measure the time it takes for the mote to sample the noise level on one channel, and move to the other.
  • Make sure you measure a value close to 5.5ms.

Testing the spectrum analyzer

  • Reprogram a second board using the code described in 4.3. Continuous Tx/Rx , so that it continuously sends data. Start the continuous sending and visualize this transmissionon the spectrum analyzer (at channel 0 by default).
  • Using the technique described in 4.2. Simple Tx/Rx , change the operating channel, and see the implications on the spectrum analyzer.
  • You can also see the impact of a running microwave oven.
When you bring the transmitting mode close to the receiver, you see on the spectrum analyzer that the signal 'leaks' over multiple channels. This is why a standard such as IEEE802.15.4 specifies the channel spacing to be 5MHz. We have set the spacing to a much lower value (200kHz) on purpose to see the effect of adjacent channel leakage. In practice, you should use frequencies which are far away from each other.

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