<< Chapter < Page Chapter >> Page >

The experimental setting goes as follows. You will have two boards, both sampling periodically sampling the channel. When they are not sampling the channel, theCC2500 is switched off and the MSP enters low-power mode. When you press a button on one board, it sends a preamble cut into 50 micro-frames; the receiverhears a micro-frame and keeps listening until it hears the last one.

To this end:

  • Program two board with the code taken from listing 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_preamble_msp . ; one will be the transmitter, the other the receiver.
  • Plug in one of the board into the computer and use PuTTY to read from its COMx port; this will be the receiver.
  • press on the transmitter's button, you should read 03 02 01 on your screen.

#include "mrfi.h" #include "radios/family1/mrfi_spi.h"void start_slow_timeout() {TACTL|=TACLR; TACCTL0=CCIE; TACTL=TASSEL_1+MC_1; }void stop_slow_timeout() {TACTL=MC_0; TACCTL0=0; }void start_fast_timeout() {TBCTL|=TBCLR; TBCCTL0=CCIE; TBCTL=TBSSEL_2+MC_1; }void stop_fast_timeout() {TBCTL=MC_0; TBCCTL0=0; }void print_counter(int8_t counter) {char output[] = {" "};output[0] = '0'+((counter/10)%10);output[1] = '0'+ (counter%10);TXString(output, (sizeof output)-1); }int main(void) {BSP_Init(); P1REN |= 0x04;P1IE |= 0x04; MRFI_Init();P3SEL |= 0x30; // P3.4,5 = USCI_A0 TXD/RXD UCA0CTL1 = UCSSEL_2; // SMCLKUCA0BR0 = 0x41; // 9600 from 8Mhz UCA0BR1 = 0x3;UCA0MCTL = UCBRS_2; UCA0CTL1&= ~UCSWRST; // Initialize USCI state machine IE2 |= UCA0RXIE; // Enable USCI_A0 RX interruptBCSCTL3 |= LFXT1S_2; TACTL=MC_0; TACCTL0=0; TACCR0=1060; //slow timeout TBCTL=MC_0; TBCCTL0=0; TBCCR0=31781; //fast timeoutstart_slow_timeout(); __bis_SR_register(GIE+LPM3_bits);} void MRFI_RxCompleteISR(){ mrfiPacket_t packet;stop_fast_timeout(); stop_slow_timeout();MRFI_Receive(&packet); if (packet.frame[9]<4) { print_counter(packet.frame[9]); start_slow_timeout();} else { MRFI_WakeUp();MRFI_RxOn(); }} #pragma vector=PORT1_VECTOR__interrupt void interrupt_button (void) {P1IFG&= ~0x04; uint8_t counter;mrfiPacket_t packet; packet.frame[0]=8+20; MRFI_WakeUp();for (counter=50;counter>=1;counter--) { packet.frame[9]=counter; MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED); }} #pragma vector=TIMERA0_VECTOR__interrupt void interrupt_slow_timeout (void) {MRFI_WakeUp(); MRFI_RxOn();start_fast_timeout(); __bic_SR_register_on_exit(SCG1+SCG0);} #pragma vector=TIMERB0_VECTOR__interrupt void interrupt_fast_timeout (void) {stop_fast_timeout(); MRFI_Sleep();__bis_SR_register_on_exit(LPM3_bits); }

Some keys for understanding the code:

  • The microcontroller handles two timeouts, one for measuring CI , the other for Dcca . Those timeouts are sourced by two different clocks: a fast and accurate clock for Dcca ; a slower, less accurate but extremely energy-efficient clock for CI . The fast clock is the Digitally Controlled Oscillator ( DCO on Timer A) while the very-low-power, low-frequency oscillator ( VLO on Timer B) is the slow clock. Because CI is triggered by the slow clock, that clock stays on all the time. Only when the slow timeout expires does the microcontroller start the fast clock to clock the fast timeout ( Dcca ); and stops it when that expires. The radio is on only during Dcca .
  • Line 38 initializes the slow timeout on Timer A
  • Line 39 initializes the slow timeout on Timer B
  • Line 42. Because the slow clock runs all the time, the board can only enter LPM3 which leaves the VLO clock running.
  • Line 71. Every time the slow timeout triggers, the CC2500 is switched on in Rx mode (lines 74-75); the fast timeout is started (line 76), and because it is clocked by the DCO, LPM0 mode is entered which leaves the DCO running (line 77).
  • Line 79. When the fast timeout expires, this timeout is stopped (line 82), the CC2500 is put to sleep (line 83) and the LPM3 mode is resumed (line 84).
  • Line 58. When the button is pressed, the board transmits 50 micro-frames, each containing a decrementing counter.

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