Jump to content

Request Assistance: Low Power Mode, Clocks, Timers

Recommended Posts

Ah. So the register is in the hardware and not in the software. Every example I have seen *appeared to me by context* to be a software thing. That would partly explain my current and continuing lack of understanding. It's surely why my searches have been a complete dud.


Let me check if I have the right general idea, before I go running off and bothering Google again (hopefully I'll be searching for the right thing soon). Basically, a register is the hardware equivalent of a variable in software. Have I got it right, more or less?


Any suggestion on search terms I can use to narrow the search results specifically for registers as they would be applied to low power modes? That might get me enough info so that I'll be able to search interrupts later and then put it all together in my head.



Link to post
Share on other sites

At least in the MSP430 architecture, a register is almost the only way for software to interact with hardware.

As an example, a hardware pin provides a set of registers, for GPIO (general purpose input/output, i.e: a digital pin) this consists of PxIN, PxOUT, PxDIR and PxREN (there are more, but these are the basic). Say, there is this pin called P1.0 on the MSP430, this means there is a port (a block of 8 pins basically) called P1 which has a pin on position 0, hence P1.0. If I want to "instruct" this port to set pin P1.0 to be an output, I write

P1DIR |= BIT0;

P1DIR means I want to instruct the port about DIRection (0 means input, 1 means output).

|= means "set the following pins (actually bits, but they mape quote good onto eachother) to a 1 (so to output).

BIT0 is equal to pin 0.

The semicolor ( ; ) indicates the end of an expression (instruction).


This basically boils down to P1DIR |= BIT0; "write a 1 to bit position 0 in register P1DIR".


PxDIR (where x is either 1 or 2 for the launchpad), sets DIRection, PxIN reads the INput, PxOUT writes the OUTput and PxREN sets Resistor ENable.


To complete this first "lesson":

P1DIR &= ~BIT0;

does the complement of P1DIR |= BIT0; so, it "write a 0 bit to position 0 in P1DIR".

Link to post
Share on other sites



Holy sweat-socks, Batman! That's a goldmine, for me. I'd hit the "Thanks" button on your post 3 times, if IPB supported it.


I think I landed there once before when looking for something else (info about the pins) and never browsed other pages or even bookmarked it.


Thanks and thanks again, gwdeveloper.






that's a nice explanation of the ports and a good example of the register that I can understand. I instantly know what those lines were in all the code examples I've seen using that format. Those lines are not heiroglyphics anymore. I fell into Energia as my IDE because I could understand how to set and use the pins via the syntax.


So, it seems that there is probably a register for LPM. Once I've found the information relating to that register and what values affect LPM in what way, I'll be writing code that sends an instruction to the hardware which alters the LPM register, and thus the LPM would change to my liking - depending on what I want it to be and when I want it to change. Is that right?


Thanks to you, too.


[edit to add]


This clears up some of the mystery around interrupts. Now it spontaneously hit me that I would use a register to set LPM to a lower state and the interrupt is used to wake it up a bit to a higher state and the MCU would do whatever I point the interrupt to. After completing whatever I have the interrupt to, the MCU could then move on to something else or go back to the function where I set the register, and thus could/would then go back to a lower LPM state.



Link to post
Share on other sites


there is a register called SR (status register) that holds results of comparison and low power configuration.

whenever you hit an interrupt, you will waffle from low power. The previous value in SR is copied to ram just before handling the interrupt. This copy is written back over SR on exit of the interrupt handling, so you'll "fall back" to low power. By changing the copy in ram before leaving the handler you can alter this behaviour.

This is exactly as you describe. Very good!

I am convinced that such understanding of what you're actually doing is essential to writing your own code, you are on the right track!

Link to post
Share on other sites

Good news for me, then!


Everyone who posted back to me in this thread have contributed (in some way) to my clearer grasp, and not just regarding LPM. This has really been eating at me for quite a while. I was getting pretty tense and stressed. I'm much more relaxed now.


Other than inviting everyone over for beer and sandwiches, I really can't express my appreciation. For me, this is HUGE!

Link to post
Share on other sites

No, I guees not. Netherlands is a bit farther than a tank of gas for me. However, I do have a few friends over there. If I find out any of them are near you, I could ask one of them to drop a six pack on your porch. I don't often use Paypal, but if you can receive ca$h, I could send enough for a tasty sip or two. That would be no problem for me.

Link to post
Share on other sites


Other than inviting everyone over for beer and sandwiches, I really can't express my appreciation. For me, this is HUGE!

No beer necessary for the crowd; that's what this community does. :-)


We'll be over Saturday, around noon for those sandwiches, though... ;-)

Link to post
Share on other sites

What MSP430 model are you using?


Download the User's Guide of your MCU family from TI, and read the chapters on power management, clocks, etc.  Basically, you need to know the chapters about the core (for 5-series, chapters 1-6).  Read them again and again until you know the subject like an expert.  That's how I did it.


Effectively, all you need to do to go into LPM is to write a certain bit pattern to the SR, but unless you know what the impact of each LPM is, what you need to do on entry & exit, etc, then you are just hacking.

Link to post
Share on other sites

I did the reading too. Stated, I did have thourough knowledge of C. I'd recommend reading chapters 1,2,5 and 8 first. Chapters 1,2 and 5 expain the basic architecture, you can save chapters 3 and 4 for later (those are about the instructionset itself, they're not vital to good design). After you have the basic architecture in mind, I recommend chapter 8, as it explanis the GPIO. You're most likely using a value line (MSP430G2xxx) chip, so use slau144 as your reference, the most recent version is slau144i.pdf

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...