DOC PREVIEW
Berkeley ELENG 290Q - Lab 1

This preview shows page 1-2-3-4-5 out of 16 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Lab 1: I/O, timers, interrupts on theeZ430-RF2500UC Berkeley - EE 290QThomas WatteyneJanuary 25, 20101 The eZ430-RF2500 and its Components1.1 Crash Course on the MSP430f2274The heart of this platform is its MSP430 microcontroller, by Texas Instruments.There is a complete family of MSP430 micro-controllers, the variants of whichare different in the amount of RAM/ROM and I/O capabilities, mainly. Theone you will program is the MSP420f2274, featuring 32KB of Flash Memory(ROM) and 1KB of RAM.The MSP430 is a 16-bit RISC microcontroller. 16-bit means that all registershold 16 bits; interconnection between the elements of the micro-controller is doneusing 16-bit buses. RISC – for Reduced Instruction Set Computer – refers tothe fact that there are (only) 27 core instructions.1.1.1 Operation of the MSP430Fig. 1 shows the internal architecture of the MSP430. The CPU contains 16registers; its operation goes as follows. A system clock ticks at a programmablerate (e.g. 1MHz), so each µs an instruction is fetched from memory (ROM),copied into the right register and executed1. An example execution can beadding two registers and copying the result to a third. In practice, these low-level details are taken care of by the compiler, which translates C into assemblerlanguage and binary code. In this tutorial, we only work with the higher-levelC.1.1.2 Programming the MSP430When you program a mote, you program its microcontroller, i.e. you put thecompiled binary code at the right location in the MSP430’s ROM memory.When the board is switched on, the MSP430 starts by fetching the first instruc-tion at a predetermined location in ROM; this is where the programming toolputs your compiled code.1Strictly speaking, instructions can take a couple of CPU cycles to execute1Figure 1: The internal architecture of the MSP430.To configure other components (e.g. to set the transmission power of theradio), you need to program MSP430 in such a way that it configures the radioat the beginning of your program.1.1.3 InterruptsA program for a wireless mote is in practice a sequence of very small piecesof code executed when some event happ ens : e.g. when the button is pressed,turn on the red LED. When an event happens in an electronic element outsidethe MSP430 (e.g. the button is pressed), this element informs the MSP430by changing the electric state of the wire which connects this element to theMSP430. This wire is connected to one of the ports of the MSP430 (e.g. portP1.2 in the case of the button on the eZ430-RF2500). You need to programthe MSP430 in such a way that changing the status on port P1.2 generatesan interrupt. When an interrupt is generated, the MSP430 stops its currentexecution (if any), and starts executing a specific function called the InterruptService Routine (ISR) asso ciated to that particular interrupt. Once this functionis finished (normally an ISR is a very small function), it resumes its normalexecution (if any).1.1.4 TimersWhen 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 timeris a 16-bit register which is incremented at each clock cycle2, i.e. once every µswith a 1MHz clock. It starts at 0, and counts up until a programmable value,2Strictly speaking, timers can be configured to count in up, down, or up/down modes,see [1]2A = 0b01101001∼A = 0b10010110A —= 0b00000010 ⇒ A=0b01101011A &= ∼0b00001000 ⇒ A=0b01100001A ∧= 0b10001000 ⇒ A=0b11100001A << 2 ⇒ A=0b10100100A >> 2 ⇒ A=0b00011010Figure 2: Binary operators used to set/reset individual bits.upon which is generates a timer interrupt, reset to 0, and starts counting upagain.1.1.5 I/O FunctionalitiesThe 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 thecase on the eZ430-RF2500 platform;• 32 have digital functions.The 32 digital pins are grouped into 4 ports of 8 pins each. Each pin has aname in the form Px.y, y represents the position of the pins within port x. Allpins can be generic I/O pins, a number of 8-bit registers are used to configurethem:• PxDIR.y s ets the direction of port Px.y; output if Px.y=1, input if Px.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 holds 8 bits, one for each pin. As a result, P1DIR=0b111100003means that pins P1.1 through P1.4 are input, while P1.5 through P1.8 are out-puts. To set/reset a specific pin, you need to use the binary operators presentedin Fig. 2.Note that most of the 32 digital pins can also be used for specific functions(SPI interface, input for Analog-to-Digital conversion, . . . ), see [2] for details.30bx means that x is written in binary; 0xx means that x is written in hexadecimal. We thushave 0x1A=0b00011010. Use Windows Calculator in Scientific mode for quick conversions.31.1.6 Low-Power OperationAs the MSP430 spends its time waiting for interrupts, it is important to reduceits energy consumption during idle periods by shutting down the clo cks youare not using. The more clocks you shut down, the less energy you use, butmake sure you leave on the clocks you need. There are four low power modes(LPM1,. . . , LPM4) which shut down different clo cks (details in [1]).In practice, you only need to leave on the auxiliary clock which clocks a timerto wake the MSP430 after some time. This is achieved by entering low-powermode 3, by adding this line at the end of you main function:bis SR register(LPM3 bits);You now know enough about the MSP430 for this tutorial, butif you want to work with the MSP430, you are strongly advised toread [1] and [2] (in that order).1.2 Crash Course on the CC2500The CC2500 is the radio chip on the eZ430-RF2500. It functions in the 2400-2483.5 MHz frequency band and provides an excellent option for WSN applica-tions because of its low-power characteristics. This chip has 20 pins:• 2 for connecting a (mandatory) 26MHz external crystal oscillator;• 2 for connecting the antenna;• 10 for powering the chip;• 6 for digital communication with the MSP430 (to be detailed in sec-tion 1.3)The chip contains 47 registers to configure operating frequency, modulationscheme, baud rate, transmission p ower, etc.


View Full Document

Berkeley ELENG 290Q - Lab 1

Documents in this Course
Lab 1

Lab 1

16 pages

Load more
Download Lab 1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lab 1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lab 1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?