<< Chapter < Page Chapter >> Page >
The goal of this section is to start using interrupts through the button on the board. You will program the board so that theLEDs change state when the button is pressed. You will also measure the energy consumed when the board sits idle, andwhen it enters a low-power mode.

Running the code

  • Copy the code presented in the following listing 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 led_button . .
  • Compile and download the code onto the board (Ctrl+D) .
  • Let the code execute (F5) , press the button on the board, the LEDs' state should change.

#include "io430.h" #include "in430.h"int main( void ) {WDTCTL = WDTPW + WDTHOLD; P1DIR |= 0x03;P1DIR&= ~0x04; P1REN |= 0x04;P1IE |= 0x04; __bis_SR_register(GIE);while(1); }#pragma vector=PORT1_VECTOR __interrupt void Port_1 (void){ P1IFG&= ~0x04; P1OUT ^= 0x03;}
Toggle LEDs state using the button

Some keys for understanding the code:

  • Lines 6 and 7 declare P1.0 and P1.1 as outputs (for the LEDs), and P1.2 as input (for the button);
  • Line 8 activates an internal resistor on P1.2 . This is needed for a button for the signal to be cleaner when the button is pressed; i.e. otherwise, the P1.2 constantly floats between high and low state. This is only needed for buttons.
  • Line 9 enables interrupts on P1.2 .
  • Line 10 enables interrupts globally.
  • Line 13 and 14 declare that this function should be called when an interrupt of type PORT1_VECTOR happens; the name Port_1 chosen has no importance.
  • Line 16 resets the interrupt flag generated (mandatory otherwise the function will be called again right after it finishes execution).

Low-power modes

As such, the board sits idle while waiting for an interrupt to happen with the MSP430 on (which continuously executed line 11). After measuring this current,you will change the code so as to enter low-power mode instead of sitting idle.

  • Using the battery unit, the resistor jumper and the oscilloscope, measure the current consumed in this mode (make sure that the LEDs are off when you measure).
  • Change line 10 by __bis_SR_register(GIE+LPM0_bits); . This instructs the MSP430 to enable the interrupts globally, and to enter LPM0 modeimmediately. Only an interrupt can wake the MSP430.
  • Remove line 11 which can never be reached.
  • Measure the current now, make sure that LEDs are again off.
  • repeat with LPM3 and LPM4.

You should obtain results close to:

Current consumed by the LPM modes
Active mode (active: CPU and all clock) 3.28mA
LPM0 mode (active: SMCLK, ACLK; disabled: CPU, MCLK) 2.88mA
LPM3 mode (active: ACLK; disabled: CPU, MCLK, SMCLK) 2.72mA
LPM4 mode (disabled: CPU and all clock) 2.72mA

Note that, because we are not using any clock in this example, we should use LPM4 as it is the most energy-efficient.

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