Tuesday, May 8, 2012

Beginning TI Launchpad

Welcome back!!!


Obviously since the first post didn't annoy you, I will try once again. This time however, I am talking not about me but about the TI launchpad. This is a very interesting little board, and I am sure you have already seen people talk about it here and there, especially on the negative side of things, but let me start off by saying....


HOLY GOD TI, WHAT THE HELL WERE YOU THINKING!?


Not about the hardware mind you, I find that these chips and the whole combo deal for $4.30/piece are one hell of a deal. Unfortunately what I do not understand is the LACK OF DOCUMENTATION for the 'hobbiest'. Now mind you if you have a bachelor's or doctorates in electrical engineering, or something then you  are probably reading this and saying 'oh god, what a prick! he doesn't know what he's saying!!'. Unfortunately I do not hold any of those things. I have a dual associates degree (soft toilet paper version at least) in computer programming and networking.


Well....


Even with this and a CCNA under my belt, I have to say this is the most ridiculous random crap splatter of documentation I have ever seen. Especially for beginners and hobbiests. Sure you may be able to read all about electrical characteristics of XYZ power by means of some crazy math that will make your brain melt, BUT YOU JUST WANNA START TOGGLING LEDS BESIDES THE ONES IT CAME WITH!


In my experience with Atmega controllers and interfacing in avr-gcc, it's pretty well documented that you address the ports and pins by hex or you can do so by binary as shown:
DDRB |= 0x00000001 (output pin 1)
DDRB  |=  0x01 (output pin 1)
DDRB  |=  0x00000010 (output pin 2)
DDRB  |=  0x02 (output pin 2)
DDRB  |=  0x00000011 (output pins 1 and 2)
DDRB  |=  0x03 (output pins 1 and 2)
and so on...

In the examples TI give you about interfacing to digital pins, they only show you how to light the two pins that are built onto the dev board as shown below:


//******************************************************************************
//  MSP430G2xx3 Demo - Software Toggle P1.0
//
//  Description; Toggle P1.0 by xor'ing P1.0 inside of a software loop.
//  ACLK = n/a, MCLK = SMCLK = default DCO
//
//                MSP430G2xx3
//             -----------------
//         /|\|              XIN|-
//          | |                 |
//          --|RST          XOUT|-
//            |                 |
//            |             P1.0|-->LED
//
//  D. Dang
//  Texas Instruments, Inc
//  December 2010
//   Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************

#include  <msp430g2553.h>

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  P1DIR |= 0x01;                            // Set P1.0 to output direction
  P1DIR |= 0x40;
  long i = 50000;
  for (;;)
  {
    i = 50000;
    P1OUT |= 0x01;                          // Toggle P1.0 using exclusive-OR
    P1OUT &=~0x40;
    do{i--;}while(i>0);
    i = 50000;
    P1OUT |= 0x40;                          // Toggle P1.6 using exclusive-OR
    P1OUT &=~ 0x01;
    do{i--;}while(i>0);
  }
}
//************************Code modified by me to bounce lights back and fourth***************
//********************Caution. I can't remember if this works right or not. *********************

Anyways with this example code, you can see that interfacing pins 1.2 and 1.6 are as follows:
    P1OUT |= 0x01;                          // Toggle P1.0 using exclusive-OR
    P1OUT |= 0x40;                       // Toggle P1.0 using exclusive-OR
So we can now depict that P1.0 = 0x01, and P1.6 = 0x40...

Now what? What about 1.1, 1.2, 1.3, etc. etc. etc?

I FOUND NOTHING ON THIS by digging all around the internet until just about an hour ago when coming across this video:


Awesome, yes that they finally explain the pin scheme, however it would be extremely nice to add that SOMEWHERE in the documentation instead of randomly finding it in a youtube video (except the guy in this video as well... he allegedly works for TI so, I suppose he knows his stuff). Mind you maybe I am just an old fuddy dud and care more to read the info on it than to watch poorly shot youtube videos of people who may or may not even know what they are talking about on such issue, but I (Finally) digress... ON WITH THE SHOW!

So from this we learn that to reference the pins on the TI chips, you do so whereby the pin number translated literally into hex:

P1.0 = P1OUT |= 0x00000001 or |= 0x01
P1.1 = P1OUT |= 0x00000010 or |= 0x02
P1.2 = P1OUT |= 0x00000100 or |= 0x04
P1.3 = P1OUT |= 0x00001000 or |= 0x08
P1.4 = P1OUT |= 0x00010000 or |= 0x10
P1.5 = P1OUT |= 0x00100000 or |= 0x20
P1.6 = P1OUT |= 0x01000000 or |= 0x40
P1.7 = P1OUT |= 0x10000000 or |= 0x80
P2.0 = P2OUT |= 0x00000001 or |= 0x01
P2.1 = P2OUT |= 0x00000010 or |= 0x02
P2.2 = P2OUT |= 0x00000100 or |= 0x04
P2.3 = P2OUT |= 0x00001000 or |= 0x08
P2.4 = P2OUT |= 0x00010000 or |= 0x10
P2.5 = P2OUT |= 0x00100000 or |= 0x20

Also....
I just found out these pins can be set high through useing 'BIT0', etc. as shown:

P1OUT |= BIT0; //Pin 1.0
P1OUT |= BIT1; //Pin 1.1
P1OUT |= BIT2; //Pin 1.2
P1OUT |= BIT3; //Pin 1.3
P1OUT |= BIT4; //Pin 1.4
P1OUT |= BIT5; //Pin 1.5
P1OUT |= BIT6; //Pin 1.6
P1OUT |= BIT7; //Pin 1.7
P2OUT |= BIT0; //Pin 2.0
P2OUT |= BIT1; //Pin 2.1
P2OUT |= BIT2; //Pin 2.2
P2OUT |= BIT3; //Pin 2.2
P2OUT |= BIT4; //Pin 2.2
P2OUT |= BIT5; //Pin 2.2
P2OUT |= BIT6; //Pin 2.2

Therefore....
Here is a program to blink ALLLLLLL PINNNNSSS in wonderful Cylon fashion :)


/*1 way cylon (not back and fourth) on MSP430 Launchpad
 * Free as in free coffee! <|0.o|>
 * Hardware Hacking Honkey 2012
*/

#include  <msp430g2553.h> //switch to whatever you use. Also remove the pins if they are not populated by the chip

void main(void) //Main for loop for the cause
{
 WDTCTL = WDTPW + WDTHOLD;  // Stops the Watch Dog Timer(WDT)
 P1DIR |= 0x01;             // Sets P1.0 to output
 P1DIR |= 0x02;             // Sets P1.1 to output
 P1DIR |= 0x04;             // Sets P1.2 to output
 P1DIR |= 0x08;             // Sets P1.3 to output
 P1DIR |= 0x10;             // Sets P1.4 to output
 P1DIR |= 0x20;             // Sets P1.5 to output
 P1DIR |= 0x40;             // Sets P1.6 to output
 P1DIR |= 0x80;             // Sets P1.7 to output
 P2DIR |= 0x01;             // Sets P2.0 to output
 P2DIR |= 0x02;             // Sets P2.1 to output
 P2DIR |= 0x04;             // Sets P2.2 to output
 P2DIR |= 0x08;             // Sets P2.3 to output
 P2DIR |= 0x10;             // Sets P2.4 to output
 P2DIR |= 0x20;             // Sets P2.5 to output
 int i = 0; //variable used in for loops.

for(;;) //For loop to infinity and beyond!!!!!!
{
for(i=0;i<10000;i++){} //for loop wastes time
P1OUT |= 0x01; //Output P1.0
for(i=0;i<10000;i++){} //for loop wastes time
P1OUT &=~ 0x01; //Stop output on P1.0
P1OUT |= 0x02; //Start output on P1.2
for(i=0;i<10000;i++){} //for loop wastes time
P1OUT &=~ 0x02; //Stop output on P1.2
P1OUT |= 0x04; //Start output on P1.3
for(i=0;i<10000;i++){} //for loop wastes time
P1OUT &=~ 0x04; //OMG your still reading these comments?  P1OUT |= 0x08;                                                     //0.p
for(i=0;i<10000;i++){} //for loop wastes time
P1OUT &=~ 0x08;
P1OUT |= 0x10;
for(i=0;i<10000;i++){} //for loop wastes time
P1OUT &=~ 0x10;
P1OUT |= 0x20;
for(i=0;i<10000;i++){} //for loop wastes time
P1OUT &=~ 0x20;
P1OUT |= 0x40;
for(i=0;i<10000;i++){} //for loop wastes time
P1OUT &=~ 0x40;
P1OUT |= 0x80;
for(i=0;i<10000;i++){} //for loop wastes time
P1OUT &=~ 0x80;
P2OUT |= 0x01;
for(i=0;i<10000;i++){} //for loop wastes time
P2OUT &=~ 0x01;
P2OUT |= 0x02;
for(i=0;i<10000;i++){} //for loop wastes time
P2OUT &=~ 0x02;
P2OUT |= 0x04;
for(i=0;i<10000;i++){} //for loop wastes time
P2OUT &=~ 0x04;
P2OUT |= 0x08;
for(i=0;i<10000;i++){} //for loop wastes time
P2OUT &=~ 0x08;
P2OUT |= 0x10;
for(i=0;i<10000;i++){} //for loop wastes time
P2OUT &=~ 0x10;
P2OUT |= 0x20;
for(i=0;i<10000;i++){} //for loop wastes time
P2OUT &=~ 0x20;
}
}




No comments:

Post a Comment