Author Topic: MSP430G2231 LaunchPad - Beginner Needs Help  (Read 19317 times)

0 Members and 1 Guest are viewing this topic.

Offline jprojectTopic starter

  • Contributor
  • Posts: 31
MSP430G2231 LaunchPad - Beginner Needs Help
« on: May 30, 2011, 07:13:09 am »
Hello everyone!

I recently got my own LaunchPad and I am very new to microcontrollers (this is actually my very first microcontroller). I just finished writing some codes in C and making it blink in various delay time but I'm having trouble understanding the coding for this microcontroller. I checked the header file msp430g2231.h but that just made me even more confused. I checked the user's manual for msp430 series but its almost 700 pages so... I was wondering if anyone can help me understand the coding for msp430 without me reading the whole manual. Right now, I just want to do simple projects like get a light sensor and make it turn on an LED when there is no light (a night light). Also, what kind of sensor (the specs of the sensor) would I need?


Thank you!
 

Offline johnboxall

  • Supporter
  • ****
  • Posts: 652
  • Country: au
  • You do nothing, you get nothing.
    • Books, services and more:
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #1 on: May 30, 2011, 07:33:37 am »
You can find good articles and some tutorials as well and a MSP430 forum at http://www.43oh.com/
« Last Edit: May 30, 2011, 07:51:10 am by tronixstuff »
 

Offline jprojectTopic starter

  • Contributor
  • Posts: 31
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #2 on: May 30, 2011, 07:50:19 am »
Thank you for the quick reply!

Here is a good link I found for beginners from the website you recommended:

http://www.43oh.com/forum/viewtopic.php?f=8&t=449&p=6346#p6346

There are many different people suggesting various ebooks and websites to get you started.
 

Offline jprojectTopic starter

  • Contributor
  • Posts: 31
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #3 on: May 30, 2011, 06:23:41 pm »
I'm still having quite a bit of trouble understanding the coding. These examples are not based off of LaunchPad and they don't explain the actual coding (like the logical operators). Can anyone help?


Thank you.

P.S. Do I need to learn all the architect of the microcontroller and the board to do small projects? I currently just finished first year electrical engineering and these microcontrollers seem like 4th year stuff. My instructor recommended me to test this out rather than playing around with arduino because it will be better in the end but it looks like it will take the whole summer to understand the LaunchPad.
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #4 on: May 30, 2011, 06:34:11 pm »
Do I need to learn all the architect of the microcontroller and the board to do small projects?

Yes.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline jprojectTopic starter

  • Contributor
  • Posts: 31
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #5 on: May 30, 2011, 06:42:35 pm »
Alright! Time to read 300 more pages on the microcontroller... yay!
 

Offline TheDirty

  • Frequent Contributor
  • **
  • Posts: 440
  • Country: ca
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #6 on: May 31, 2011, 01:09:15 pm »
Did you try googling msp430 tutorial or launchpad msp430 tutorial?  It looks like there are quite a few out there.

http://www.egarante.net/2010/09/msp430-launchpad-tutorial-part-1-basics.html
http://e2e.ti.com/videos/m/microcontroller/208276.aspx

If you are moving from another microcontroller, it should not be difficult at all to look up the specifics of the peripherals in the F2xxx user guide.  If you are starting from scratch, working with any microcontroller without abstract libraries like an Arduino is going to be difficult to get up to speed on.

I would also suggest using TI's sample peripheral code as a base when trying out something new.
http://focus.ti.com/mcu/docs/mcuprodcodeexamples.tsp?sectionId=96&tabId=1468
Mark Higgins
 

Offline tsmz

  • Contributor
  • Posts: 30
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #7 on: June 01, 2011, 01:22:39 am »
I don't think you need to read the microcontroller manuals yet. They're recommended reading for sure, especially the family user's guide. However, before reading it, make sure you find out exactly which modules your microcontroller has, as the family user's guide is rather large and you wouldn't want to read everything on modules you'll never be able to use.

I get the impression you don't know terribly much about C programming. This is absolutely required before doing anything with microcontrollers, even with systems like the arduino, which is basically just a set of very high-level hardware-abstracted C/C++ libraries. You can find many C tutorials online, and it's important to know your C when getting into microcontrollers.

TI's examples are a mixed bag, I don't personally find them very informative at times. However, there's a lot of code on the web and TI's launchpad wiki contains links to other ressources, which you should check out.
 

Offline jprojectTopic starter

  • Contributor
  • Posts: 31
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #8 on: June 01, 2011, 01:59:51 am »
Did you try googling msp430 tutorial or launchpad msp430 tutorial?  It looks like there are quite a few out there.

http://www.egarante.net/2010/09/msp430-launchpad-tutorial-part-1-basics.html
http://e2e.ti.com/videos/m/microcontroller/208276.aspx

If you are moving from another microcontroller, it should not be difficult at all to look up the specifics of the peripherals in the F2xxx user guide.  If you are starting from scratch, working with any microcontroller without abstract libraries like an Arduino is going to be difficult to get up to speed on.

I would also suggest using TI's sample peripheral code as a base when trying out something new.
http://focus.ti.com/mcu/docs/mcuprodcodeexamples.tsp?sectionId=96&tabId=1468

The Enrico Garante site has helped me a lot! Understood it so easily. Thank you.


I don't think you need to read the microcontroller manuals yet. They're recommended reading for sure, especially the family user's guide. However, before reading it, make sure you find out exactly which modules your microcontroller has, as the family user's guide is rather large and you wouldn't want to read everything on modules you'll never be able to use.

I get the impression you don't know terribly much about C programming. This is absolutely required before doing anything with microcontrollers, even with systems like the arduino, which is basically just a set of very high-level hardware-abstracted C/C++ libraries. You can find many C tutorials online, and it's important to know your C when getting into microcontrollers.

TI's examples are a mixed bag, I don't personally find them very informative at times. However, there's a lot of code on the web and TI's launchpad wiki contains links to other ressources, which you should check out.

I am familiar with the C/C++ language (studied up to the point where I am able to make a search/store database program) but there are some codes that I have never seen before such as these bitwise assignment operators (|=, &=, ^=). Why do we need these?. Also, I have never seen these "~" in C programming but I've seen them quite a bit in the MSP430 source files in front of the pin addresses. I decided to experiment and ran the source code without "~" in front of the addresses and it made no difference so I'm confused why they are needed in the first place.

As for the module, I currently have the MSP430G2231 LaunchPad (like the title of the topic says :P) so that should explain everything.

Yes, I checked the TI video tutorials but it is quite confusing at times because they tell you to look at the example and the TI manual without any reference to page number or section of the manual. I did find them after few minutes of reading through the titles of the chapters but not helpful at all unless if you are familiar with the architect of the whole MSP430!
 

Offline 8086

  • Super Contributor
  • ***
  • Posts: 1084
  • Country: gb
    • Circuitology - Electronics Assembly
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #9 on: June 01, 2011, 02:11:09 am »
I am familiar with the C/C++ language (studied up to the point where I am able to make a search/store database program) but there are some codes that I have never seen before such as these bitwise assignment operators (|=, &=, ^=). Why do we need these?. Also, I have never seen these "~" in C programming but I've seen them quite a bit in the MSP430 source files in front of the pin addresses. I decided to experiment and ran the source code without "~" in front of the addresses and it made no difference so I'm confused why they are needed in the first place.

"~" means invert all the bits in the operand, I believe.
 

Offline jprojectTopic starter

  • Contributor
  • Posts: 31
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #10 on: June 01, 2011, 02:26:29 am »
So if I do ~0x001 it will equal 11...10? I still don't understand because I programmed my MCU with an example code after taking out the "~" and it worked perfectly fine. GRRR so confusing!
 

Offline 8086

  • Super Contributor
  • ***
  • Posts: 1084
  • Country: gb
    • Circuitology - Electronics Assembly
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #11 on: June 01, 2011, 02:30:43 am »
It may be that the line of code did not alter anything in the program's main functionality.

Could you post the line in question, including a few on either side of it?
 

Offline jprojectTopic starter

  • Contributor
  • Posts: 31
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #12 on: June 01, 2011, 02:44:47 am »
Here it is, it's from http://www.egarante.net/2010/09/msp430-launchpad-tutorial-part-1-basics.html


#include <msp430g2231.h>


int main(void)  //Main program
{
 WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
 
 P1DIR |= BIT0; // Set P1.0 to output and P1.3 to input direction
 P1OUT &= ~BIT0; // set P1.0 to Off
 P1IE |= BIT3; // P1.3 interrupt enabled
 P1IFG &= ~BIT3; // P1.3 interrupt flag cleared
 
 __bis_SR_register(GIE); // Enable all interrupts
 
 while(1) //Loop forever, we'll do our job in the interrupt routine...
 {}
}

#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
    P1OUT ^= BIT0;  // Toggle P1.0
    P1IFG &= ~BIT3; // P1.3 interrupt flag cleared
}


If you are not familiar with the header file, BIT0 to BIT# means
BIT0 = 0x0001u (this is the address for the LED)
BIT1 = 0x0002u
BIT2 = 0x0004u
BIT3 = 0x0008u (this is the address for the switch button)
etc...
 

Offline TheDirty

  • Frequent Contributor
  • **
  • Posts: 440
  • Country: ca
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #13 on: June 01, 2011, 05:03:13 pm »
~ inverts the number, so

BIT3 = 00001000
~BIT3 = 11110111

So (11110111 & variable) clears the bit in variable.

I'm not certain what happens if you don't clear the interrupt flag.  I guess nothing if it still works fine, but without clearing the interrupt flag you can't check to see which interrupt initiated the ISR since the flag is left high.
Mark Higgins
 

Offline jahonen

  • Super Contributor
  • ***
  • Posts: 1054
  • Country: fi
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #14 on: June 01, 2011, 07:38:07 pm »
If the port interrupt flag is not cleared at end of the ISR on a MSP430, the MCU will immediately re-enter the ISR upon return from it.

Regards,
Janne
 

Offline jprojectTopic starter

  • Contributor
  • Posts: 31
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #15 on: June 01, 2011, 08:08:34 pm »
This is the code I used to programme the MCU and it works exactly like the original code posted above (push the switch to toggle the red LED).


#include <msp430g2231.h>


int main(void)  //Main program
{
 WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
 
 P1DIR = BIT0; // got rid of OR assignment "|="
 P1OUT &= BIT0; // got rid of "~"
 P1IE = BIT3; // got rid of OR assignment "|="
 P1IFG &= ~BIT3; // P1.3 interrupt flag cleared
 
 __bis_SR_register(GIE); // Enable all interrupts
  //Got rid of while loop
}

#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
    P1OUT ^= BIT0;  // Toggle P1.0
    P1IFG &= ~BIT3; // P1.3 interrupt flag cleared
}


Now, why does this do the exactly the same thing as the original code?
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11630
  • Country: my
  • reassessing directives...
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #16 on: June 01, 2011, 09:02:40 pm »
I am familiar with the C/C++ language (studied up to the point where I am able to make a search/store database program) but there are some codes that I have never seen before such as these bitwise assignment operators (|=, &=, ^=).
no! you are not familiar with C, esp you are not familiar with binary operation. you maybe an expert database programmer, but to become mcu programmer, you need to master number crunching in binary! and i'm not the one :P once you've done with binary operation, then yea! you can read the manual of what bit in the register do what.
« Last Edit: June 01, 2011, 09:12:13 pm by Mechatrommer »
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline jprojectTopic starter

  • Contributor
  • Posts: 31
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #17 on: June 01, 2011, 09:13:50 pm »
I am familiar with the C/C++ language (studied up to the point where I am able to make a search/store database program) but there are some codes that I have never seen before such as these bitwise assignment operators (|=, &=, ^=).
no! you are not familiar with C, esp you are not familiar with binary operation. you maybe an expert database programmer, but to become mcu programmer, you need to master number crunching in binary! and i'm not the one :P


Haha yeeeee! I am very new to MCU programming. I must get "dirty" as my instructor would say and learn up to the binary parts of the MCU. Any good sites or ebooks you would recommend for MCU programming? I am currently just reading over the MSP430 Microcontroller Basics ebook.
 

alm

  • Guest
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #18 on: June 01, 2011, 09:17:16 pm »
I agree with the other people that a good grasp on C, especially the bitwise operators, is critical for MCU programming in C. Learning aspects of C on a PC is usually easier than on a micro because debugging and testing on a PC tend to be much easier. This tutorial on bitwise operators might be a good read. Bitwise operators have been a standard part of C since K&R C, so they work the same in all compilers on all platforms. Nothing AVR specific about that tutorial.
 

Offline jprojectTopic starter

  • Contributor
  • Posts: 31
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #19 on: June 01, 2011, 09:31:35 pm »
I agree with the other people that a good grasp on C, especially the bitwise operators, is critical for MCU programming in C. Learning aspects of C on a PC is usually easier than on a micro because debugging and testing on a PC tend to be much easier. This tutorial on bitwise operators might be a good read. Bitwise operators have been a standard part of C since K&R C, so they work the same in all compilers on all platforms. Nothing AVR specific about that tutorial.

Thank you for the link! I am getting directed in the right direction which is very good. Here is also a link I would like to add for bitwise in C:



Pretty much the same as the forum except extra explanation and video format.
 

Offline baljemmett

  • Supporter
  • ****
  • Posts: 665
  • Country: gb
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #20 on: June 01, 2011, 09:34:07 pm »
P1DIR = BIT0; // got rid of OR assignment "|="
 P1OUT &= BIT0; // got rid of "~"
 P1IE = BIT3; // got rid of OR assignment "|="

Now, why does this do the exactly the same thing as the original code?

Well, to be honest, rather than answer your question it might be better to ask you one in return: under what conditions would those changes result in no change in behaviour?  An understanding of the bitwise operators is, as has been pointed out, essential to the sort of register manipulations you'll need to be doing when you work with a microcontroller.  Since you seem to understand already what the various bitwise and assignment operators do, it shouldn't be too tricky to reason about the differences your changes made :)
 

Offline jprojectTopic starter

  • Contributor
  • Posts: 31
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #21 on: June 01, 2011, 09:56:49 pm »
P1DIR = BIT0; // got rid of OR assignment "|="
 P1OUT &= BIT0; // got rid of "~"
 P1IE = BIT3; // got rid of OR assignment "|="

Now, why does this do the exactly the same thing as the original code?

Well, to be honest, rather than answer your question it might be better to ask you one in return: under what conditions would those changes result in no change in behaviour?  An understanding of the bitwise operators is, as has been pointed out, essential to the sort of register manipulations you'll need to be doing when you work with a microcontroller.  Since you seem to understand already what the various bitwise and assignment operators do, it shouldn't be too tricky to reason about the differences your changes made :)



BIT0 = 0x0001 = 0000 0001
BIT3 = 0x0008 = 0000 1000


Original:
P1DIR |= BIT0;   //I'm assuming since all pins are set on input on default, P1DIR will be 0000 0000
       //P1DIR |= BIT0 will equal P1DIR = 0000 0000 | 0000 0001 which equals 0000 0001
P1OUT &= ~BIT0;    //Since BIT0 is set to output, I'm assuming P1OUT = 0000 0001
       //P1OUT &= ~BIT0 equals P1OUT = 0000 0001 & 1111 1110 which equals 0000 0000
P1IE |= BIT3;    //*I am not sure what P1IE value is at the beginning but I'm assuming it would be
       //either 0000 0000 or 0000 1000


My Editted Version:
P1DIR = BIT0;   // got rid of OR assignment "|="
P1OUT &= BIT0;  // got rid of "~"
P1IE = BIT3;    // got rid of OR assignment "|="

Which also means:
P1DIR = 0000 0001
P1OUT = P1OUT & 0000 0001  //Does P1OUT == 0000 0001? If so then the final P1OUT is 0000 0001
P1IE = 0000 1000


Please do correct me if I am wrong! As always, thank you.
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11630
  • Country: my
  • reassessing directives...
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #22 on: June 01, 2011, 10:13:00 pm »
Any good sites or ebooks you would recommend for MCU programming? I am currently just reading over the MSP430 Microcontroller Basics ebook.
ere let me google for you, type "binary arithmetic operation bitwise etc". some random search...
http://atrevida.comprenica.com/atrtut02.html
http://www.doc.ic.ac.uk/~eedwards/compsys/arithmetic/index.html
and then read your C/C++ book (on bitwise section), buy one if you still dont have. and then your MSP430#!@$@!#$ datasheet. and then the example you already found out. and then alot of practice! good luck ;)
« Last Edit: June 01, 2011, 10:16:31 pm by Mechatrommer »
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11630
  • Country: my
  • reassessing directives...
Re: MSP430G2231 LaunchPad - Beginner Needs Help
« Reply #23 on: June 01, 2011, 10:18:44 pm »
ok i see where's you getting now. i suggest you try to simulate the value in your pc environment. try to make a pc program that will show the binary value during debugging. so you can check your mistake faster.
P1OUT &= ~BIT0 ... p1out = p1out and (not bit0)
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf