Skip to content

Latest commit

 

History

History
151 lines (99 loc) · 4.13 KB

msp430_workshop_notes_2-27-2011.md

File metadata and controls

151 lines (99 loc) · 4.13 KB
layout title
default
MSP430 Workshop notes 2/27/2011 - Collexion

MSP430 Workshop notes 2/27/2011

Here are the notes from our TI MSP430 programming workshop, held 2/27/2011. Our goal was to get working build environments on our PCs and be able to program the LED on the ez430 development sticks from Texas Instruments. We succeeded!

##Code

Once compiled, you can use mspdebug's 'prog' command to load the .elf binary onto the device:

mspdebug -d /dev/ttyUSB0 uif 'prog blinky430.elf'

Here's the blinky code we used to test the toolchain, modified from TI's blinky code to make it more readable for non-C programmers:

/*

blinky430.c

*/ #include <msp430x20x3.h>

void main(void) { // The watchdog timer will periodically reset the chip if we haven't poked it // Initialize the WDT (WDTPW) and turn that behavior off (WDTHOLD) WDTCTL = WDTPW + WDTHOLD;

// Mark P1.0 as an output pin by setting P1DIR's LSB to 1
P1DIR = P1DIR | 0x01;

while (1)	// Infinite loop
{
	// Flip LED state
	// Invert pin P1.0, port 1 bitwise XOR with 0000 0001
	P1OUT = P1OUT ^ 0x01;

	// Wait
	i = 20000;
	while ( i > 0 ) {
		i--;
	}
}

}

And here's some code that can make the LED pulse up and down, rather than flash on and off:

/*

pulse430.c

*/ #include <msp430x20x3.h>

// Constants for pulse width increment and cycle time (sum of LED on + off time) #define INCR 1 #define CYCLE 250

void main(void) { // The watchdog timer will periodically reset the chip if we haven't poked it // Initialize the WDT (WDTPW) and turn that behavior off (WDTHOLD) WDTCTL = WDTPW + WDTHOLD;

// Mark P1.0 as an output pin by setting P1DIR's LSB to 1
P1DIR = P1DIR | 0x01;

// Starting value for the LED pulse width
unsigned int width = 11;

// Per-cycle pulse width delta (how much longer to stay lit each cycle)
unsigned int incr = INCR;

// Loop counter
unsigned long i;

while (1)	// Infinite loop
{

	// == LED ON ==
	// Turn on pin P1.0, port 1 bitwise OR with 0000 0001
	P1OUT = P1OUT | 0x01;

	// Wait
	i = width;
	while ( i > 0 ) {
		i--;
	}

	// == LED OFF ==
	// Turn off pin P1.0, port 1 bitwise AND with 1111 1110
	P1OUT = P1OUT & 0xFE;

	// Wait out the remainder of the cycle
	i = CYCLE - width;
	while ( i > 0 ) {
		i--;
	}

	// == UPDATE PULSE WIDTH ==
	width += incr;

	// If we've hit the minimum or maximum pulse width, start moving the width
	// in the other direction
	if ( width >= CYCLE - 30 || width < 1) {
		incr = -incr;
	}

}

}

##Links

###Tools