turd 31 Posted November 7, 2011 Share Posted November 7, 2011 Hello, Where could I find example code that works with mspgcc? I've been using the PICAXE chips for years now and I use FreeBASIC quit a bit but thats all just BASIC. I've played around with the Arduino a bit but thats the only C experience I have. Is there maybe some documentation or even some tutorials out there? Thank you Quote Link to post Share on other sites
chibiace 46 Posted November 8, 2011 Share Posted November 8, 2011 take a look at: http://hackaday.com/2010/08/11/how-to-launchpad-programming-with-linux/ http://processors.wiki.ti.com/index.php/MSP430_LaunchPad_(MSP-EXP430G2)#Download_all_MSP430G2xx_code_examples get a make file and your program usually main.c, edit up your code. 1. make 2. sudo mspdebug rf2500 'prog main.elf' here is a little something i made for use as a template: main.c #include "signal.h" #include "io.h" void delay(register unsigned int t) {register unsigned int i; for (i = 0; i < t*100; i++){}} void main(){ WDTCTL = WDTPW + WDTHOLD; // Turn off watchdog timer. P1DIR |= BIT0+BIT6; // Set P1.0 & P1.6 as output. int a=0; while (a==0){ // Loop P1OUT |= BIT0+BIT6; // Turn P1.0 & P1.6 on. delay(100); P1OUT &= ~BIT0+BIT6; // Turn P1.0 & P1.6 off. delay(100); }} and Makefile CC=msp430-gcc CFLAGS=-Os -Wall -g -mmcu=msp430x2012 OBJS=main.o all: $(OBJS) $(CC) $(CFLAGS) -o main.elf $(OBJS) %.o: %.c $(CC) $(CFLAGS) -c $< clean: rm -fr main.elf $(OBJS) bluehash and turd 2 Quote Link to post Share on other sites
rockets4kids 204 Posted November 8, 2011 Share Posted November 8, 2011 Most of TI's sample code code for CCS/IAR will compile under mspgcc by changing only the interrupt syntax. mspgcc provides an abstraction for interrupt handling in isr_compat.h but this hasn't worked for me. Instead, I just use the following code block: #if defined (__GNUC__) // mspgcc #include #define ISR(a, void __attribute__((interrupt (a))) b (void) #else // CCS/IAR #include #define __PRAGMA__(x) _Pragma(#x) #define ISR(a, \ __PRAGMA__(vector=a) \ __interrupt void b(void) #endif You define an ISR like this: ISR (PORT1_VECTOR, port1_isr) { // isr here } The following Makefile may also be of interest: PROG = hk8 CC = msp430-gcc CXX = msp430-g++ OBJDUMP = msp430-objdump SIZE = msp430-size MSPDEBUG = mspdebug CFLAGS = -O0 -Wall -g -mmcu=msp430g2211 FET = rf2500 GDB = msp430-gdb GDBTUI = $(GDB)tui OBJS=$(PROG).o all: $(PROG).elf $(PROG).lst $(SIZE) $(PROG).elf .PHONY: all $(PROG).elf: $(OBJS) $(CC) $(CFLAGS) -o $(PROG).elf $(OBJS) %.o: %.c $(CC) $(CFLAGS) -c $< %.lst: %.elf $(OBJDUMP) -DS $< >$@ clean: rm -fr *.o *.elf *.lst *~ \#* install: $(PROG).elf $(MSPDEBUG) $(FET) "prog $(PROG).elf" mspdebug: $(PROG).elf $(MSPDEBUG) $(FET) debug: $(PROG).elf $(MSPDEBUG) $(FET) gdb gdb: $(PROG).elf $(GDB) $(PROG).elf tui: $(PROG).elf $(GDBTUI) $(PROG).elf ddd: $(PROG).elf ddd --debugger $(GDB) $(PROG).elf turd 1 Quote Link to post Share on other sites
turd 31 Posted November 8, 2011 Author Share Posted November 8, 2011 Thanks guys! I've followed the Hack a Day example and I've been able to run their example code Ya, I always get errors to do with interrupts so your posts will be a big help! I found a pdf tutorial on the forum called "Beginning Microcontrollers with the MSP430 Tutorial" and it's pretty good. This is going to save me a bit of time : sudo mspdebug rf2500 'prog main.elf' Thanks again for the code, template and make files! Quote Link to post Share on other sites
gordon 229 Posted November 8, 2011 Share Posted November 8, 2011 2. sudo mspdebug rf2500 'prog main.elf' http://mspdebug.sourceforge.net/faq.html#usb_noroot turd 1 Quote Link to post Share on other sites
turd 31 Posted November 8, 2011 Author Share Posted November 8, 2011 Thanks for the link gordon! I'm having some trouble getting this example from "Beginning Microcontrollers with the MSP430 Tutorial" to work: http://www.glitovsky.com/Tutorialv0_3.pdf page 43. (slightly modified) #include #include #include void configureClocks(); volatile unsigned int i; // volatile to prevent optimization void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer configureClocks(); // Configure LED on P1.0 P1DIR = BIT0; // P1.0 output P1OUT &= ~BIT0; // P1.0 output LOW, LED Off // Configure Switch on P1.2 // P1REN |= BIT3; //Enable Pullup/Pulldown P1OUT = BIT3; //pullup P1IE |= BIT3; //interrupt enabled P1IES |= BIT3; //Hi/lo falling edge P1IFG &= ~BIT3; //IFG cleared just in case _EINT(); while(1) { // Execute some other code } } void configureClocks() { // Set system DCO to 8MHz BCSCTL1 = CALBC1_8MHZ; DCOCTL = CALDCO_8MHZ; // Set LFXT1 to the VLO @ 12kHz BCSCTL3 |= LFXT1S_2; } // Port 1 interrupt service routine IRS(PORT1_VECTOR, port1_isr) { P1OUT ^= BIT0; // Toggle LED at P1.0 P1IFG &= ~BIT3; // P1.2 IFG cleared } msp430-gcc -Os -Wall -g -mmcu=msp430x2012 -c expl.cexpl.c:8: warning: return type of Quote Link to post Share on other sites
bluehash 1,581 Posted November 8, 2011 Share Posted November 8, 2011 IRS(PORT1_VECTOR, port1_isr) You have a typo... IRS turd 1 Quote Link to post Share on other sites
turd 31 Posted November 8, 2011 Author Share Posted November 8, 2011 I changed it but I'm still getting errors: #include #include #include void configureClocks(); volatile unsigned int i; // volatile to prevent optimization void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer configureClocks(); // Configure LED on P1.0 P1DIR = BIT0; // P1.0 output P1OUT &= ~BIT0; // P1.0 output LOW, LED Off // Configure Switch on P1.2 // P1REN |= BIT3; //Enable Pullup/Pulldown P1OUT = BIT3; //pullup P1IE |= BIT3; //interrupt enabled P1IES |= BIT3; //Hi/lo falling edge P1IFG &= ~BIT3; //IFG cleared just in case _EINT(); while(1) { // Execute some other code } } void configureClocks() { // Set system DCO to 8MHz BCSCTL1 = CALBC1_8MHZ; DCOCTL = CALDCO_8MHZ; // Set LFXT1 to the VLO @ 12kHz BCSCTL3 |= LFXT1S_2; } // Port 1 interrupt service routine IRS(PORT1_VECTOR, port1_irs) { P1OUT ^= BIT0; // Toggle LED at P1.0 P1IFG &= ~BIT3; // P1.2 IFG cleared } msp430-gcc -Os -Wall -g -mmcu=msp430x2012 -c expl.cexpl.c:9: warning: return type of Quote Link to post Share on other sites
turd 31 Posted November 8, 2011 Author Share Posted November 8, 2011 I got it #include #include #include void configureClocks(); volatile unsigned int i; // volatile to prevent optimization void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer configureClocks(); // Configure LED on P1.0 P1DIR = BIT0; // P1.0 output P1OUT &= ~BIT0; // P1.0 output LOW, LED Off // Configure Switch on P1.2 // P1REN |= BIT3; //Enable Pullup/Pulldown P1OUT = BIT3; //pullup P1IE |= BIT3; //interrupt enabled P1IES |= BIT3; //Hi/lo falling edge P1IFG &= ~BIT3; //IFG cleared just in case _EINT(); while(1) { // Execute some other code } } void configureClocks() { // Set system DCO to 8MHz BCSCTL1 = CALBC1_8MHZ; DCOCTL = CALDCO_8MHZ; // Set LFXT1 to the VLO @ 12kHz BCSCTL3 |= LFXT1S_2; } // Port 1 interrupt service routine interrupt(PORT1_VECTOR) port1_irs (void) { P1OUT ^= BIT0; // Toggle LED at P1.0 P1IFG &= ~BIT3; // P1.2 IFG cleared } Quote Link to post Share on other sites
bluehash 1,581 Posted November 9, 2011 Share Posted November 9, 2011 Apparently I was in the wrong... but kuddos! you solved it. Quote Link to post Share on other sites
turd 31 Posted November 9, 2011 Author Share Posted November 9, 2011 Thanks bluehash Here's an unrelated question; with the Launch Pad, could you fry P1.3 if it was set as an out put and it was high and you ground it out by pressing the button attached to it? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.