<< Chapter < Page Chapter >> Page >

You will write ISRs in to response when pushing the button ( 3.3 ), timer interrupts ( 3.4 ) and when receiving a packet at the radio ( 4.2 ).

Timers

When writing code, you may want to wait some time before doing something (e.g. when I receive a packet, wait 10ms, and send a reply packet). This can bedone using a timer, a specific component of the MSP430. Physically, a timer is a 16-bit register which is incremented at each clock cycle, i.e. once every μswith a 1MHz clock. It starts at 0, and counts up until a programmable value, upon whichis generates a timer interrupt, reset to 0, and starts counting up again.

You will use timer in section to have a LED flash at a given rate ( 3.4 ).

I/o functionalities

The MSP430 has 40 pins:

  • 4 have analog functions to power the board;
  • 2 are used for testing at the factory;
  • 2 are used if an external crystal is used as clock source, which is not the case onthe eZ430-RF2500 platform;
  • 32 have digital functions.

The 32 digital pins are grouped into 4 ports of 8 pins each. Each pin has a name inthe form Px.y , y represents the position of the pins within port x . All pins can be generic I/O pins, a number of 8-bit registers are used to configure them:

  • PxDIR.y sets the direction of port PxDIR.y ; output if PxDIR.y=1 , input if PxDIR.y=0 ;
  • PxOUT.y sets the state of port Px.y when set as output;
  • PxIN.y reads the state of port Px.y when set as input;
  • PxIE.y enables interrupts on that port;

Each of these registers hold 8 bits, one for each pin. As a result, P1DIR=0b11110000 0bx means that x is written in binary; 0xx means that x is written in hexadecimal. We thus have 0x1A=0b00011010 . Use Windows Calculator in Scientific mode for quick conversions. means that pins P1.0 through P1.3 are input, while P1.4 through P1.7 are outputs. To set/reset a specific pin, you need to use the binary operators presented inthe following code:

Assuming A = 0b01101001, we have:~A = 0b10010110 A |= 0b00000010: A=0b01101011A&= ~0b00001000: A=0b01100001 A ^= 0b10001000: A=0b11100001A<<2: A=0b10100100 A>>2: A=0b00011010
Binary operators used to set/reset individual bits.

Note that most of the 32 digital pins can also be used for specific functions (SPIinterface, input for Analog-to-Digital conversion, ...), see the MSP430x22x2, MSP430x22x4 Mixed Signal Microcontroller datasheet for details.

Low-power operation

As the MSP430 spends its time waiting for interrupts, it is important to reduce itsenergy consumption during idle periods by shutting down the clocks you are not using. The more clocks you shut down, the less energy you use, but make sure youleave on the clocks you need. There are four low power modes (LPM1, ..., LPM4) which shut down different clocks (details in the MSP430x2xx Family User's Guide ).

In practice, you only need to leave on the auxiliary clock which clocks a timer towake the MSP430 after some time. This is achieved by entering low-power mode 3, by adding this line at the end of your main function:

__bis_SR_register(LPM3_bits);
You now know enough about the MSP430 for this tutorial, but if you want towork with the MSP430, you are strongly advised to read the MSP430x2xx Family User's Guide and the MSP430x22x2, MSP430x22x4 Mixed Signal Microcontroller datasheet (in that order).

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