Jump to content
43oh

jsolarski

Members
  • Content Count

    568
  • Joined

  • Last visited

  • Days Won

    8

Reputation Activity

  1. Like
    jsolarski reacted to simpleavr in General Purpose I/O control over serial?   
    the closest thing i can think of is joby's launchpad spi explorer.
     
    http://blog.hodgepig.org/2010/09/10/575/
     
    it's kind of pc side uart driving the launchpad to do spi control on other devices connecting to the launchpad in a spi bus.
     
    it's an interactive shell where you issue commands via a terminal program and have specific syntax similar to bus pirate, etc.
     
    the codes are very well organized and it's easy to re-purpose it as the the command parsing is inside parse.c and parse.h.
  2. Like
    jsolarski reacted to Lizard787 in NES Controller   
    The program reads an NES Controller. The Data pin is connected to P1.0, the latch pin is connected to P1.1 and the Clock Pin is connected to P1.2. I'm using the controller adapter from parallaxhttp://www.parallax.com/Store/Accessories/HumanInterfaceDevices/tabid/822/CategoryID/90/List/0/SortField/0/Level/a/ProductID/613/Default.aspx to hook up the controllers. After it is done reading the controller it jumps to the subroutine "Finished".
    The inputs are stored in Register 12 which goes:
    A B Select Start UP DOWN LEFT RIGHT
    1 is pressed, 0 is unpressed.

    #include "msp430.h" ; #define controlled include file NAME main ; module name PUBLIC main ; make the main label vissible ; outside this module ORG 0FFFEh DC16 init ; set reset vector to 'init' label RSEG CSTACK ; pre-declaration of segment RSEG CODE ; place program in 'CODE' segment init: MOV #SFE(CSTACK), SP ; set up stack ;42 If Button Press main: CLR.B &P1DIR ;41 If No Button Press BIS.B #7Fh, &P1DIR ; main program ADD.B #7Fh, &P1DIR CLR.B &P1OUT BIS.B #02h, &P1OUT ;Latch Up CLR R4 CLR R13 ;Button State CLR R12 ;All values stored CLR R5 ;Counter BIS.B &P1IN, R13 ;Gets data1 status ;02 is button pressed 03 is not BIS.B #03h, R4 ;Math to get button status SUB.B R13, R4 CLR.B &P1OUT CMP.B #01h, R4 ;Compare values JNE NextButton ADD.B #01h, R12 NextButton: ;67 althogether (A pressed) 15 or 16 INC.B R5 ;Counter CMP #08h, R5 ;Checks How many times loop has run JEQ Finished ;Insert To whereever you want to go after inputs read CLR R13 ;Reset CLR R4 RLA.B R12 ;Rotate for new value ADD.B #04h, &P1OUT ;Clock High BIS.B &P1IN, R13 ;Gets INput CLR.B &P1OUT;Clock Low CMP.B #04h, R13 JNE NextButton ADD.B #01h, R12 JMP NextButton END
    When I tested it I connected four LEDS on pins P1.4 to P1.7 and added the code. Since I only added four led's it only outputs either the multi directional button presses or the normal(A B Start Select) button. IF you try this code make sure you erase the END command on the first section of code i posted.

    Finished: CMP #10h, R12 JLO Displaay BIS.B R12, &P1OUT JMP main Displaay: RLA.B R12 RLA.B R12 RLA.B R12 RLA.B R12 BIS.B R12, &P1OUT JMP main END
    EDIT: Optimized the code(Removed 1 instruction). EDIT 2: Removed another instruction
  3. Like
    jsolarski reacted to RobG in LaunchPad, 74HC165, Switches   
    *******************
    Also checkout this post
    *******************
     
    In this example, I am demonstrating how to connect switches using parallel-serial shift register 74HC165.
    You can daisy chain as many 165s as you want.
    In my example I have 2 of them, which allowes me to connect up to 16 switches.
    In the video, I am using small 6 position DIP switch and all unused inputs are grounded and do not have pull-up resistors.
    Also, the state of switches is displayed on a 7 segment display (see my other post for how to connect 7 segment display.)
    De-bouncing is accomplished by comparing previous state with current (switchReady.)
     


     

    #include unsigned int data = 0; // data to be displayed unsigned int digitCounter = 0; // Digit counter unsigned char digit = 0; // Single digit to be displayed unsigned char hex7digit[16] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x58,0x5E,0x79,0x71}; // Hex to 7 digit map unsigned char digitSelector[4] = {0x01, 0x02, 0x04, 0x08}; // Digit selector map unsigned int switchReady = 0x0; // When BITn is 0, means switch is unstable H->L or L->H unsigned int switchStatus = 0x0; // Pressed or released void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1OUT |= 0x01; // Port P1.0 will be used to latch both, 74HC165 and 74HC595 P1DIR |= 0x01; USICTL0 |= USIPE7 + USIPE6 + USIPE5 + USIMST + USIOE; // In, out & clk enable, SPI Master USICTL1 |= USICKPH + USIIE; // Counter interrupt, flag remains set USICKCTL = USIDIV_4 + USISSEL_2; // /16 SMCLK USICTL0 &= ~USISWRST; // USI released for operation USICNT = USI16B; // Enable 16 bit CCTL0 = CCIE; // CCR0 interrupt enabled CCR0 = 625; // Approx. 5ms TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode _bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt WDTCTL = WDTPW + WDTHOLD; // Stop WDT } // Timer A0 interrupt service routine #pragma vector = TIMERA0_VECTOR __interrupt void Timer_A (void) { //P1OUT &= ~0x01; // You could latch input right now //P1OUT |= 0x01; if(digitCounter == 0) { // Update switch status every 20 ms switchReady = ~(USISR ^ switchStatus); // Copy USI's register to switchReady and switchStatus switchStatus = USISR; if((switchReady & 0x3F) == 0x3F) { // When all 6 switches are ready... data = switchStatus; // move input to data } } digitCounter++; // Increase digit counter digitCounter &= 0x03; // Mask, counter range is 0-3 digit = data>>(4 * digitCounter); // Shift digits right digit &= 0x0F; // Mask, we need first digit only USISRL = hex7digit[digit]; // Get segments from the map USISRH = digitSelector[digitCounter]; // USICNT |= 16; // Start USI } // USI interrupt service routine #pragma vector = USI_VECTOR __interrupt void USI_TXRX (void) { USICTL1 &= ~USIIFG; // Clear pending flag P1OUT &= ~0x01; // Latch data display (& input for next timer interrupt) P1OUT |= 0x01; }
     
    Schematic:

  4. Like
    jsolarski reacted to simpleavr in ezprobe, ez430 based logic probe   
    here is my entry to the december project of the month. comments welcomed.
     

     
    description
     
    this is a simple logic probe project based on TI Launchpad. i took advantage of a free offer on a couple of ez430s from TI in september 2010. they are very handy and fun in trying out small code snippets and watch the led blink. they had since been laying around my desk and i have to come up with something for them. and i want to stop people coming up and ask to borrow my "memory stick".
     
    well, this is no memory stick, 16bit MCU w/ multi-channel ADCs, adaquate 2K programming memory and runs up to 16Mhz. all packed up with the debugging programming interface board in a nice usb device package.
     
    my main design goal is to limit my intervention to the original ez430. in that i don't want do alter it too much physically and i want to retain it's programming / debugging function for other target board projects. all this while serve additional useful purposes.
     
    this is a linux project, as usual, i had given attention with my best knowledge to make provisions so that it can be built under windows. however i do not have the time and resources to try out everything under windows.
     
    most of my electronics projects are done on very small breadboards and i usually work on tight spaces (kitchen table, half a borrowed desk, etc). there are many instances that i need to check circuit logic levels and i've been using a multimeter (size of a brick) to check things out. it always annoys me as my projects are much smaller than my multimeter and i found it always gets in my way. i need an alternative, a small logic probe will do.
     
    the ez430 is perfect for this task. to begin with, it's already shaped like a probe, i just need to add a nail and some leds. as i mentioned earlier, i want to make this project simple and non-destructive. and i made use of what's available already.
     
    instead of building the project on a pcb / pref-board, i build this on a target msp430f2012 board, employing the 14 pin header thru holes as my prototyping area. this is where the tiny leds goes. i do not want to drill holes on the plastic casing, i don't want to run too many wire nor add additional contact points. all i need is a probe io contact and a button input for function select, plus gnd and vcc. the usb connection looks perfect for this task. i will power the probe via the usb (the programmer circuit will regulate a around 3v potential for me) and use the D+ and D- usb connects for my probe and switch.
     
    since the ez430 is slave / client device, upon initialization, it won't do a thing except a pull-up on D+ (to indicate it's a "hi-speed" usb). i use the floating D- as my probe io and D+ as my tactile button input (i don't even need to setup a pull-up resistor for that, it's already there)
     
    features and application
     
    * supply from circuit via usb connector
    * 3 operating modes rotating between logic read, pulse output, pwm output
    * long button press (about 1.5 sec) rotates through the 3 operating modes
    * p1.0 original green led as mode indicator, off - probe, on - output, blink - pwm
     
    logic probe
     
    * logic probe red - hi, green - low, none - floating
    * logic probe red / green blinks on continous pulse reads > 100hz
    * 4 yellow leds shows detected frequencies in 8 steps, blinking yellows indicate hi-range (i.e. step 5-8)
    * shows detected pulse frequences for 100hz+, 500hz+, 1khz+, 5khz+, 10khz+, 50khz+, 100khz+, 500khz+
    * for non-continous single pulse bursts, the red / green leds stays on and subsequent pulse counts are displayed incrementally on the leds, will count up to 8 pulse
     
    continuous pulse output, frequency setting
     
    * indicated by p1.0 original green led on
    * 4 yellow leds shows output pulse frequencies in 9 steps, blinking yellows indicate hi-range (i.e. step 5-8)
    * pulse frequences output for 100hz, 500hz, 1khz, 5khz, 10khz, 50khz, 100khz, 500khz, 1mhz
    * short button press rotates the 9 different frequency settings.
    continuous pulse output, pwm setting
     
    * indicated by p1.0 original green led blinking
    * same as previous operation mode, except pwm values are show (and be setup) instead of frequency
    * 4 yellow leds shows output pwm percentages in 9 steps, blinking yellows indicate hi-range (i.e. step 5-8)
    * pwm percentages for 0%, 12.5%, 25%, 37.5%, 50%, 62.5%, 75%, 87.5%, 100%
    * short button press rotates the 9 different pwm settings.
     
    schematic

     
    source file
    ezprobe.zip
     


     
    project page, construction details, schematics, etc.
    http://www.simpleavr.com/msp430-projects/ezprobe
     
    [EDIT] source code and schematic added, update more correct schematic
  5. Like
    jsolarski reacted to RobG in LaunchPad and fun with the flash (strobe & slave trigger)   
    Last weekend I was doing a little photo shoot and I was in need of extra flash source. I have an old Nikon SB-28 laying around so I figured I could use it if I had a slave trigger. Sure I can buy one from Amazon for <$10 (dumb one) or build one using 555 (which would ignore TTL pre-flash,) but why not go one step further and use LaunchPad.
     
    Step 1, build strobe light.
    This is pretty simple, just add opto-isolator and write short program.
    FL1 connects to the center pin of the hot shoe, FL2 to the side.
    If you need a hot shoe, you can get one cheap from BHPhotoVideo.com, just search for AS-E900 (or SK-E900, you'll get nice bracket as a bonus!)




    #include unsigned int sw = 0; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1OUT |= 0x01; // Port P1.0 will be used to trigger flash P1DIR |= 0x01; CCTL0 = CCIE; // CCR0 interrupt enabled CCR0 = 20000; // TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK, upmode _bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt } // Timer A0 interrupt service routine #pragma vector = TIMERA0_VECTOR __interrupt void Timer_A (void) { if(sw = ~sw) { // Flash every other interrupt P1OUT |= 0x01; } else { P1OUT &= ~0x01; } }
     
    Step 2, add S2 to control speed.
     

    #include unsigned int counter = 0; unsigned int resetCounterAt = 100; unsigned int pressedS2 = 0; // BITn of switchReady and switchStatus corresponds to Port P1.n unsigned int switchReady = 0x0; // When BITn is 0, means switch is unstable H->L or L->H unsigned int switchStatus = 0x0; // Pressed or released void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1OUT |= BIT0; // Port P1.0 will be used to trigger flash P1DIR |= BIT0; P1DIR &= ~BIT3; // Port P1.3 as input P1OUT |= BIT3; // Pull up resistor P1REN |= BIT3; // Enable pull up resistor CCTL0 = CCIE; // CCR0 interrupt enabled CCR0 = 1250; // Approx. 10ms TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode // we will use USI as a delay USICTL0 |= USIMST; // SPI Master USICTL1 |= USICKPH + USIIE; // Counter interrupt USICKCTL = USIDIV_4 + USISSEL_2; // SMCLK/16 USICTL0 &= ~USISWRST; // USI released for operation _bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt } // Timer A0 interrupt service routine #pragma vector = TIMERA0_VECTOR __interrupt void Timer_A (void) { switchReady = ~(P1IN ^ switchStatus); switchStatus = P1IN; if(switchReady & BIT3 && !(switchStatus & BIT3)) { if(!pressedS2) { // Update only once resetCounterAt -= 20; if(resetCounterAt < 20) { resetCounterAt = 100; } pressedS2 = 1; // Set pressedS2 flag } } if(switchReady & BIT3 && switchStatus & BIT3) pressedS2 = 0; // S2 released, clear pressedS2 flag counter++; if( counter > resetCounterAt ) { counter = 0; P1OUT |= BIT0; // Flash on interrupt USICNT |= 8; // Start delay } } // USI interrupt service routine #pragma vector = USI_VECTOR __interrupt void USI_TXRX (void) { USICTL1 &= ~USIIFG; P1OUT &= ~BIT0; // Clear P1.0 }
     
     
    Step 3, add phototransistor to make it work as a slave trigger
    Since 70's are long gone, I don't think I will have any use for the strobe, so we will add phototransistor to make it work as a dumb slave trigger


    #include void main(void) { WDTCTL = WDTPW + WDTHOLD; // stop WDT P1OUT &= ~BIT0; // port P1.0 will be used to trigger flash P1DIR |= BIT0; P1DIR &= ~BIT7; // port P1.7 input P1IE |= BIT7; // P1.7 interrupt enabled P1IES &= ~BIT7; // P1.7 lo/high edge P1IFG &= ~BIT7; // P1.7 IFG cleared _bis_SR_register(LPM0_bits + GIE); // LPM0 with interrupts } // Port 1 interrupt service routine #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { P1IE &= ~BIT7; // disable P1.7 interrupt P1IFG &= ~BIT7; // P1.7 IFG cleared P1OUT |= BIT0; // flash on interrupt _no_operation(); // 1 cycle delay, just in case //__delay_cycles(50); // if there are problems wih trigger, longer delay may be needed P1OUT &= ~BIT0; // clear P1.0 P1IE |= BIT7; // enable P1.7 interrupt }
     
     
    Step 4, add delay to make it work with TTL pre-flash
    Since in TTL mode main flash is not the first one, we have to add delay to ignore pre-flash(s)
     
    As it turns out, this is not an easy task. Pre-flashes are far more complicated than I thought and simple delay may not work.
    So this is my first stab at it. I am simply ignoring first flash and triggering the slave on second one. If there's no second flash within 200ms, counter is reset. This setup works with my D80 and SB-28 in TTL mode except when flashing too close to detector.
     
    When I find some extra time, I will improve this thing or hopefully someone else will contribute.
     

    #include unsigned char mainFlash = 0; // 0 indicates pre-flash, 1 main flash void main(void) { WDTCTL = WDTPW + WDTHOLD; // stop WDT P1OUT &= ~BIT0; // port P1.0 will be used to trigger flash P1DIR |= BIT0; P1DIR &= ~BIT7; // port P1.7 input P1IE |= BIT7; // P1.7 interrupt enabled P1IES &= ~BIT7; // P1.7 lo/high edge P1IFG &= ~BIT7; // P1.7 IFG cleared CCTL0 = CCIE; // CCR0 interrupt enabled CCR0 = 0; // timer idle TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, up mode _bis_SR_register(LPM0_bits + GIE); // LPM0 with interrupts } // Port 1 interrupt service routine #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { P1IE &= ~BIT7; // disable P1.7 interrupt P1IFG &= ~BIT7; // P1.7 IFG cleared if(mainFlash) { // this is a main flash, trigger slave P1OUT |= BIT0; // trigger slave _no_operation(); // 1 cycle delay, just in case P1OUT &= ~BIT0; // clear P1.0 mainFlash = 0; // clear flag CCR0 = 0; // no need for timer } else { // pre-flash CCR0 = 25000; // start timer, approx. 200ms mainFlash = 1; // set flag } P1IFG &= ~BIT7; // P1.7 IFG cleared P1IE |= BIT7; // enable P1.7 interrupt } // Timer A0 interrupt service routine #pragma vector = TIMERA0_VECTOR __interrupt void Timer_A (void) { if(mainFlash) { // for some reason, there was no main flash mainFlash = 0; // reset flag CCR0 = 0; // no need for timer } }
  6. Like
    jsolarski got a reaction from rivalslayer in Debouncing in external interrupts   
    you could use the WDT timer or timer_A, depends on what you have available. the other option is turn off the interrupt for just that interrupt and re-enable it right before the interrupt returns. I think the best bet is to use the WDT timer for a delay instead of a SW delay. There are other ways for de-bouncing but this is just my opinion.
  7. Like
    jsolarski reacted to NatureTM in Flashing the missing DCO calibration constants   
    EDIT: Here's another really nice DCO calibration program. It's part of TinyOS-msp430. http://code.google.com/p/tinyos-msp430/ It's the file called calibrate-dco. As gordon, who discovered it said, "[it] appears to be a quite beefed-up DCO calibration app, with goodies on the side (taking silicon errata into account for various devices when calibrating)." It looks like it's built to be solid and reliable. I skimmed over the code and didn't see anything for calculating SegA checksum, but that usually isn't an issue for most non-critical applications.
     
    EDIT: maxpenna shared another version of the DCO calibration program. This is the one to use if you need a correct SegmentA checksum. It uses the C calibration function. You can get it here http://www.43oh.com/forum/download/file.php?id=292
     
    WARNING: Some of the programs in this thread will erase Segment A and only put back the DCO calibrations. They should not be used with chips that have an ADC12, as this process will destroy the ADC12 calibrations. Some of the programs do not calculate the Segment A checksum, so the integrity of Segment A cannot be verified during runtime after calibration. Still, I've been using it without any problems.
     
     
    There's been a bit of a discussion in another thread about an idea simpleavr had for adding the dco calibration constants to flash for the Value Line series. I've cobbled together some pieces of TI code and have it working. It seems to work great. Here's how I did it with CCS. I think the people on linux should be able to reproduce the result with a little adaptation.
     
    This requires the TI DCO library I modified in another thread and an external LF crystal like the one with Launchpad.
    http://naturetm.com/files/Launchpad%20setDCO%20lib.rar
     
    First, run this to calibrate the constants and write them to flash:
    EDIT: 43oh member zeke has made some changes to the code for finer tuning. Check page 2 for his code.

    //****************************************************************************** // MSP430F20xx Demo - DCO Calibration Constants Programmer // // NOTE: THIS CODE REPLACES THE TI FACTORY-PROGRAMMED DCO CALIBRATION // CONSTANTS LOCATED IN INFOA WITH NEW VALUES. USE ONLY IF THE ORIGINAL // CONSTANTS ACCIDENTALLY GOT CORRUPTED OR ERASED. // // Description: This code re-programs the F2xx DCO calibration constants. // A software FLL mechanism is used to set the DCO based on an external // 32kHz reference clock. After each calibration, the values from the // clock system are read out and stored in a temporary variable. The final // frequency the DCO is set to is 1MHz, and this frequency is also used // during Flash programming of the constants. The program end is indicated // by the blinking LED. // ACLK = LFXT1/8 = 32768/8, MCLK = SMCLK = target DCO // //* External watch crystal installed on XIN XOUT is required for ACLK *// // // MSP430F20xx // --------------- // /|\| XIN|- // | | | 32kHz // --|RST XOUT|- // | | // | P1.0|--> LED // | P1.4|--> SMLCK = target DCO // // A. Dannenberg // Texas Instruments Inc. // May 2007 // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.42A //****************************************************************************** #include "msp430x20x1.h" #include "DCO_Library.h" unsigned char CAL_DATA[8]; // Temp. storage for constants volatile unsigned int i; int j; char *Flash_ptrA; // Segment A pointer void Set_DCO(unsigned int setting); void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT for (i = 0; i < 0xfffe; i++); // Delay for XTAL stabilization P1OUT = 0x01; // Red LED on P1SEL = 0x10; // P1.4 SMCLK output P1DIR = 0x51; // P1.0,4,6 output j = 0; // Reset pointer Set_DCO(TI_DCO_16MHZ); // Set DCO and obtain constants CAL_DATA[j++] = DCOCTL; CAL_DATA[j++] = BCSCTL1; Set_DCO(TI_DCO_12MHZ); // Set DCO and obtain constants CAL_DATA[j++] = DCOCTL; CAL_DATA[j++] = BCSCTL1; Set_DCO(TI_DCO_8MHZ); // Set DCO and obtain constants CAL_DATA[j++] = DCOCTL; CAL_DATA[j++] = BCSCTL1; Set_DCO(TI_DCO_1MHZ); // Set DCO and obtain constants CAL_DATA[j++] = DCOCTL; CAL_DATA[j++] = BCSCTL1; Flash_ptrA = (char *)0x10C0; // Point to beginning of seg A FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator FCTL1 = FWKEY + ERASE; // Set Erase bit FCTL3 = FWKEY + LOCKA; // Clear LOCK & LOCKA bits *Flash_ptrA = 0x00; // Dummy write to erase Flash seg A FCTL1 = FWKEY + WRT; // Set WRT bit for write operation Flash_ptrA = (char *)0x10F8; // Point to beginning of cal consts for (j = 0; j < 8; j++) *Flash_ptrA++ = CAL_DATA[j]; // re-flash DCO calibration data FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCKA + LOCK; // Set LOCK & LOCKA bit P1OUT = 0; while (1) { P1OUT ^= BIT6; // Toggle green LED for (i = 0; i < 0x4000; i++); // SW Delay } } void Set_DCO(unsigned int setting){ volatile unsigned int I; // P1DIR |= BIT0; // P1.0 output BCSCTL1 &= ~XTS; // external source is LF; BCSCTL3 &= ~(LFXT1S0 + LFXT1S1); // watch crystal mode BCSCTL3 |= XCAP0 + XCAP1; // ~12.5 pf cap on the watch crystal as recommended for( I = 0; I < 0xFFFF; I++){} // delay for ACLK startup if(TI_SetDCO(setting) == TI_DCO_NO_ERROR) // if setting the clock was successful, P1OUT |= BIT0; // bring P1.0 high (Launchpad red LED) else while(1); // trap if setting the clock isn't successful }
     
    The green light should start blinking in a few seconds, indicating success. Now we need to modify some linker and header files so CCS knows about the new calibrations.
     
    I'm using the MSP430G2231, so I duplicated the file C:\Program Files (x86)\Texas Instruments\ccsv4\msp430\include\msp430g2231.cmd in that directory, and renamed the duplicate as msp430g2231_mod.cmd. Now I can edit it without affecting the original. Edit msp430g2231_mod.cmd and change the calibration section at the bottom to this:
     

    /************************************************************ * Calibration Data in Info Mem ************************************************************/ CALDCO_16MHZ = 0x10F8; CALBC1_16MHZ = 0x10F9; CALDCO_12MHZ = 0x10FA; CALBC1_12MHZ = 0x10FB; CALDCO_8MHZ = 0x10FC; CALBC1_8MHZ = 0x10FD; CALDCO_1MHZ = 0x10FE; CALBC1_1MHZ = 0x10FF;
     
    Now the linker knows we have calibration data in that section when we use the modified file.
     
    When we create a new project in CCS or modify an existing one, CCS will want to use the default linking file, and the default header. Here's an example about how to configure a project to use the new constants.
    First create a new project. Within the project, there should be a file called something like lnk_msp430g2231.cmd. The last line of that file should be something like -l msp430g2231.cmd. Open it, and change the last line to reflect the new linker file so it reads -l msp430g2231_mod.cmd.
    Next, add the appropriate header file to the project. Right-click the project folder in the left pane of CCS and click "Add files to project..." In this example, I'm using C:\Program Files (x86)\Texas Instruments\ccsv4\msp430\include\msp430g2231.h. Now we have a copy of the file in the project we can safely edit. Edit the file so the calibration section looks like this:

    /************************************************************ * Calibration Data in Info Mem ************************************************************/ #ifndef __DisableCalData SFR_8BIT(CALDCO_16MHZ); /* DCOCTL Calibration Data for 16MHz */ SFR_8BIT(CALBC1_16MHZ); /* BCSCTL1 Calibration Data for 16MHz */ SFR_8BIT(CALDCO_12MHZ); /* DCOCTL Calibration Data for 12MHz */ SFR_8BIT(CALBC1_12MHZ); /* BCSCTL1 Calibration Data for 12MHz */ SFR_8BIT(CALDCO_8MHZ); /* DCOCTL Calibration Data for 8MHz */ SFR_8BIT(CALBC1_8MHZ); /* BCSCTL1 Calibration Data for 8MHz */ SFR_8BIT(CALDCO_1MHZ); /* DCOCTL Calibration Data for 1MHz */ SFR_8BIT(CALBC1_1MHZ); /* BCSCTL1 Calibration Data for 1MHz */ #endif /* #ifndef __DisableCalData */
     
    Now you can begin using the new calibration data in your program. When you #include the msp430g2231.h file, put it in quotes instead of <> to ensure it's loading the modified header local to the project directory.
     
    I tested the constants with a cheap oscilloscope and they seemed correct. My scope doesn't have great accuracy at high frequencies so they might be a little off, but nothing I can detect. It works with my composite video prog, so that's a pretty good sign.
     
    EDIT: Oops! I had an incorrectly named file in these instructions. Corrected.
  8. Like
    jsolarski reacted to NatureTM in Launchpad TV output   
    I got my Launchpad to output B/W composite video. It only displays one image without re-flashing though, so it's not extremely useful. The only external components are two resistors and a crystal oscillator. I plan on writing it up on my blog and releasing the source sometime this week, unless I get too busy with school. I wasn't sure if I'd be able to ever get this working, so I'm feelin' pretty good right now!
    Proof ;-)

     
    Code for use with an external oscillator:
    Launchpad_TV_Out.rar
     
    Code for if you have your DCO configuration constants calibrated:
    Launchpad_TV_Out_for_calibrated.rar
     
    EDIT: Here's the writeup!
    http://naturetm.com/?p=47
  9. Like
    jsolarski reacted to juani_c in Connector for 2013 target board with staples   
    In case somebody want to use that Launchpad's feature I made the connector with some 26/6 staples
     

     

     

  10. Like
    jsolarski reacted to cde in Powering LEDs With MSP430 Output   
    First of all, how many do you plan on using?
     
    Second, resistors on leds are primarily for current control, as an led will pull as much current as it can, and burn out if it pulls too much. Voltage control is secondary.
     
    Next, do you plan on driving each at full brightness/current? They are listed at 20ma. If you power them directly from the msp430 at 20ma, the voltage will drop between 2.7 (5ma) and 2.5 volts (25ma), which might not be enough to turn on the led.
    From a TI forum post, not specifically about the launchpad/valueline msp430s, but similar (and the valuelines act the same)
    http://e2e.ti.com/support/microcontroll ... 75002.aspx
     
    The msp430g2231 Datasheet has the graphs on page 40. Since the launchpad runs at 3.5v and not 3v, there is a tiny bit more leeway, but essentially, more than ~48ma output current (sourcing) on a port will make the high level/1 voltage 0.
    http://focus.ti.com/lit/ds/symlink/msp430g2231.pdf
     
    Essentially, you could power an led at 20ma and it might light up, or you could power a handful at 5ma, but it won't be at full brightness. And you just won't be able to power any leds in series, or parallel from the same pin really.
     
    Mostly, you'll need transistors.
     
    Interestingly enough
    http://processors.wiki.ti.com/index.php ... _Drive_LED
    seems to say that the maximum current per pin is 1.5 ma to maintain the maximum output voltage
  11. Like
    jsolarski got a reaction from simpleavr in how many launchpads did u order?   
    @simpleavr
    i can send you one of my launchpads if you would like to play with one, sry it has been used once but still (dis)un-assembled.
    I would send the crystal and headers and the 2231chip and what ever else i can find that came with it.
    let me know if your interested
  12. Like
    jsolarski reacted to bluehash in IRC   
    ... and we have IRC. See Announcement
  13. Like
    jsolarski reacted to Joby Taffey in GoodFET   
    Hi,
     
    I've reflashed the IM-Me using GoodFET. It's pretty easy. I'm using Linux, but it may also be possible from Windows.
     
    I have a GoodFET31. It wasn't too hard to assemble, but if you haven't tried surface mount soldering before then you might want to read up on it first (use plenty of flux and get a fine tipped iron). Travis Goodspeed will send you a PCB for $5 (or nothing if you're a student).
     
    The IM-Me chip is a CC1110, which is an 8051 based microcontroller. SDCC does support this, but MSPGCC is for MSP430 only.
     
    The GoodFET supports MSP430 JTAG, but I haven't tried it out yet.
     
    For goodfet questions #goodfet on irc.freenode.org is a good place. It's pretty quiet, but if you leave your message in the channel someone will usually respond eventually.
  14. Like
    jsolarski got a reaction from bluehash in American Design style contest STM32   
    http://stm32challenge.net
     
    should be interesting
  15. Like
    jsolarski reacted to gatesphere in MSP430G2xxx Tea Timer   
    Here is my entry for the November 2010 Project of the Month Contest, an MSP430G2xxx based tea timer!
     
    I love tea, and thought this contest was an excellent reason to actually get off of my lazy behind and put this together.
     
    Below is my blog post on it, modified slightly to show the pictures and code here rather than just link to them as on my blog. Blog post is available here: http://blog.suspended-chord.info/?c=27
     
    Below this point is the post:
    ------------------------------------------------------
    Hello all,
     
    I am an avid tea drinker. As such, I make many cups of various kinds of tea, each with their own optimal steep times. Usually, I just keep track of the time, but I have found that I can make the best cup of tea by setting a timer to go off after a certain amount of time, depending on the style of tea that I am brewing. I find the best results come from going by the following table (based on personal preference and experimentation):
     
     
    Tea Variety => Recommended Steep Time
    White tea => 2 minutes
    Green tea => 3 minutes
    Black/Oolong tea => 4 minutes
    Herbal tea/infusions (most varieties) => 5 minutes
    Rooibos tea (African redbush) => 6 minutes
    Chai tea (regardless of base) => 8 minutes
    Kukicha twig tea and other varieties => in intervals of 1 minute
     
     
    With this in mind, I decided that I should make a tea timer. This seems simple enough, and it has been on my to-do list for a while anyway, and 43oh! is having an MSP430 Project of the Month Contest, so I decided to hack it together. Turned out rather simple.
     


    The full part count is as follows:
    [*:3snbat08] 3 toggle switches (or a 3-switch DIP, as I used)
    [*:3snbat08] 4 10k resistors
    [*:3snbat08] 1 5mm green LED
    [*:3snbat08] 1 piezo buzzer with integrated driver circuit
    [*:3snbat08] 1 tact switch/push button
    [*:3snbat08] wire
    [*:3snbat08] Any MSP430 uC with at least 1k flash and a TimerA module (though I could have hacked the WDT to work)
     
    So, I assembled the circuit on my breadboard, following the schematic at the end of my post, and programmed the MSP430.
     
    For the code, I borrowed beretta's TimerA code example, and tweaked it to fit the needs of my timer. The timer is to read the input value of the three switches as a binary value to determine tea type, set a "goal" amount of half-second ticks based upon the user's request, and when the user presses the "start" button, go into a waiting period. While the uC is waiting, the LED will be flashed slowly at first, but increasingly faster as the timer ticks closer to the goal. Once the goal amount of ticks has been reached, the LED will be turned on, and the buzzer will sound (mine sounds reminiscent of an old-fashioned tea kettle, so it's suitable). The buzzing can be stopped by pressing the "start" button again to reset the device, and allow another time to be set. Simple enough, right?
     
    The code is available:

    // MSP430 based Tea Timer // Sets off a buzzer to let you know when your tea is done steeping // Supports several types of tea // suspended-chord (http://blog.suspended-chord.info) /* Tea steeping chart Tea type Time DIP Code ------------------------------------------ White 2 minutes 000 Green 3 minutes 001 Black/Oolong 4 minutes 010 Herbal 5 minutes 011 Chai 8 minutes 100 Rooibos 6 minutes 101 Other 1 minute 110 Other 2 30 seconds 111 */ // circuit: // LED on P1.0 // Piezo buzzer with driver on P1.1 // 3-switch dip (or 3 toggle switches) on P1.4, P1.5, and P1.6 // push button tact on P1.3, pullup resistor //#define DEBUG #define __MSP430G2231__ #include // pin for status LED #define LED BIT0 // pin for buzzer #define BUZZER BIT1 // pin for start switch #define START BIT3 // three consecutive pins for mode selection #define INPUT1 BIT4 #define INPUT2 BIT5 #define INPUT3 BIT6 // numeric value of the first pin #define SHIFT 4 // unused bits #define UNUSED BIT2 + BIT7 // variables unsigned int goal = 0; unsigned int tickCount = 0; unsigned char statusCount = 0; char statusMode = 0; char mode = 0; char reset = 0; volatile unsigned int i = 0; void main() { while(1) { WDTCTL = WDTPW + WDTHOLD; // kill wdt P1OUT = 0; // clear outputs P1DIR = LED + BUZZER + UNUSED; // setup outputs and unused to out/low to reduce power consumption BCSCTL1 = CALBC1_1MHZ; // setup DCO DCOCTL = CALDCO_1MHZ; // setup TimerA TACCR0 = 62499; // .5s cycle with 1MHZ clk and /8 divider // delay a few cycles to debounce i = 0; while (i < 50000) i++; while ((P1IN & START) == START) { // keep setting mode until start switch is pressed // setup mode mode = (P1IN & (INPUT1 + INPUT2 + INPUT3)) >> SHIFT; // setup goal switch (mode) { case 0: // white tea goal = 240; // 2 minutes break; case 1: // green tea goal = 360; // 3 minutes break; case 2: // black/oolong tea goal = 480; // 4 minutes break; case 3: // herbal tea goal = 600; // 5 minutes break; case 4: // chai tea goal = 960; // 8 minutes break; case 5: // rooibos tea goal = 720; // 6 minutes break; case 6: // other goal = 120; // 1 minute break; case 7: // other2 goal = 60; // 30 seconds break; default: goal = 0; } } #ifdef DEBUG goal = 30; // 15 seconds #endif // reset the TAR, and finish setting up TimerA TACTL = TASSEL_2 + ID_3 + MC_1 + TACLR; // select SMCLK/8, up mode, and clear the TAR TACCTL0 = CCIE; // enable interrupts // enable interrupts _enable_interrupt(); // turn on LED P1OUT |= LED; // reset variables statusCount = statusMode = tickCount = reset = 0; // enter LPM1 //LPM1; while (reset == 0); } } // timerA interrupt for CCR0 #pragma vector = TIMERA0_VECTOR __interrupt void CCR0_ISR (void) { tickCount++; // increase tick count // toggle LED increasingly faster as the time counts towards the end statusCount++; if (tickCount >= goal/4) statusMode = 1; if (tickCount >= goal/2) statusMode = 2; if (tickCount >= 3*(goal/4)) statusMode = 3; switch (statusMode) { case 0: if (statusCount >= 4) { // blink every 2 seconds P1OUT ^= LED; // toggle LED statusCount = 0; } break; case 1: if (statusCount >= 3) { // blink every 1.5 seconds P1OUT ^= LED; // toggle LED statusCount = 0; } break; case 2: if (statusCount >= 2) { // blink every 1 second P1OUT ^= LED; // toggle LED statusCount = 0; } break; case 3: default: // blink every .5 second P1OUT ^= LED; // toggle LED statusCount = 0; break; } if (tickCount >= goal) { _disable_interrupt(); // kill interrupts TACCTL0 &= ~CCIE; // disable TimerA CCR0 interrupt //LPM1_EXIT; // exit LPM1 P1OUT |= LED + BUZZER; // buzzer + LED on while ((P1IN & START) == START); // if START pressed, return to main() reset = 1; } }
     
    Basically, as I stated above, the user selects a mode (tea type) by way of the three switches, and then presses a button to start the timer. When the tea is done steeping, the buzzer goes off, and the user can press the button again to reset it. The switch positions corresponding to the tea types are as follows:
     
    6, 5, and 4 refer to P1.6, P1.5, and P1.4
    6 5 4 Tea type (time)
    0 0 0 White Tea (2 minutes)
    0 0 1 Green Tea (3 minutes)
    0 1 0 Black/Oolong Tea (4 minutes)
    0 1 1 Herbal Tea/Infusions (5 minutes)
    1 0 0 Chai Tea (8 minutes)
    1 0 1 Rooibos Tea (6 minutes)
    1 1 0 Other1 (1 minute)
    1 1 1 Other2 (30 seconds)
     
     
    Now, this isn't the most accurate timer, as I'm not using the crystal, but it's accurate enough to steep a good cup of tea (believe me, I've used it a lot since I hacked it together), and my stopwatch tells me it's accurate to within around 6 seconds on average.
     
    In the future, I'd like to use a better input mechanism (I might be geeky enough to remember binary codes for tea types, but most are not, so a rotary switch or something would be perfect), maybe a cheap LCD for a status indicator, even showing how much time remains, and potentially having the last two codes (110 and 111) be user programmable for any time in second increments up to half of an unsigned long (as the ticks are half-second ticks). Maybe even shove it all into an Altoids tin for portability and the geek-chic factor. Who knows?
     
    Anyways, here's the schematic, and a photo of it in action:
     

    Tea-Timer in action! (notice the LaunchPad is only used as a power supply here... I don't have a battery clip yet.)
     

    schematic
     
    Thanks for reading!
     
    Keep tweaking~
     
    EDIT: I'm an idiot sometimes... I forgot the code and images.
  16. Like
    jsolarski reacted to paradug in 32k crystal install and test   
    You might find this instructable step informative with regards to the 32k crystal.
    http://www.instructables.com/id/MSP430-Based-Chronulator-using-Launchpad-chip/step11/Determining-the-32768-kHz-Crystals-load-Capacita/
     
    It explains why the crystal's load capacitance needs to be right. It also gives a way that you can check if you have a freq. meter.
  17. Like
    jsolarski reacted to cde in SMD Size Reference   
    Numbers are misleading. What you may think is big (or small) enough in your head, might not be the right size. Visuals help.
     
    Edit: Update Below.
     

     
    Clockwise from top:
    DIP 8pin IC (100 mil Lead spacing)
    Sot-23 3pin Transistor (50 mil Lead Spacing, due to 3 pin configuration, pin 1 and 3 are 100 mils apart)
    0805 Capacitor
    Soic(Wide) 28pin IC (50 mil Lead Spacing)
    2pin 100x100 mil Header
    1206 Capacitor
     
    On a 2010 Penny for the size reference. The 1206 and Sot23 cover the date exactly. The 0805 isn't big enough to do that.
     
    The 0805's solder pads fit on the Soic's 50 mil spaced leads exactly. If you don't want to dedicate a pad to a decoupling 0805, just solder it straight onto the pins (if you ever find an IC with V+ and Gnd right next to each other that is).
     
    Same goes for the 1206 and the DIP's 100 mil spaced leads.
     
    You can even use a 2pin header to make a smd to through-hole adapter if you don't have the needed through-hole version. Both the 1206 and the 0805 (barely) can be done. Even the Sot-23, if you use 3 inline header pins and a bit of wire.
     
    Sot-23 has the same spacing as a Soic package ic. With the 3-pin parts, the middle pin of one side is removed, while the outer two pins on the other side are removed as well, so it has a 100 mil spacing on the side with 2 pins. The 4-pin version has 3 pins on one side, with an extra big pin on the other side (heat dissipation purposes normally). The 5-pin version has all 3 pins on one side and the 2 outer pins on the other side. The 6-pin version has a full set of pins on both sides. Even though sot-23 and soic have the same pin spacing and sizes, Soic chips, having a bigger body, are easier to handle. Even sop/ssop/tssop parts, with 25 mil spaced pins, are easier to handle than sot-23 6 pin imho.
     
    Lesson is really, stick to through hole for prototyping till you are ready to beta. Sot23 is hella tiny, and I would have not gone with it for the transistors I bought if I had known (The standard to-92 versions were the same price, and have higher watt ratings to boot). Ha.
     
    ---
     
    It happened again. I was expecting a decent sized QFP chip. I got:

     
    A 3mm x 3mm package QFN with pin spacing smaller than tssop, in a reflow only package. Oh vey.
  18. Like
    jsolarski reacted to cde in Choosing a MSP430 chip   
    Found this nice brochure on TI's site.
     
    http://focus.ti.com/lit/sg/slab034s/slab034s.pdf
     
    A complete breakdown of the various msp430 chips, what peripherals they has, and what those peripherals do as well as explaining the different LPM Modes. Well, except for the most important question to us, SBW capability.
     
    Interesting to note, there is quite a bit of overlapping of the MSP430G line and the MSP430F20xx line. Basically, all of the basic options (Different type of ADC on 2 parts is the only difference), except that the Valueline chips are just cheaper (And apparently, use less power too). I expect the F20xx line to be obsoleted eventually in favor of the ValueLine chips.
    Edit: The F20xx line can come in better temperature rating -40 to 105c, vs -40 to 85c)
     
    Aside from the MSP430G and F20xx lines which come in nice PDIP and SOIC packages, there is the MSP430F21x1 Line. Also comes in SOIC, has more gpio/flash/ram than the Gxx or F20xx lines, but no hardware UART/SPI/I2C or good ADC, but worst of all, NO SPY-BI-WIRE, ie, no launchpad/ez430 support. Avoid the MSP430F21x1 Line of chips unless you want to buy a new programmer. For the same reason, avoid the entire MSP430F1xxx Family.
     
    The next step above the Gxx and F20xx line that we can use is the MSP430F21x2 line. It's like doubling a Gxxx chip. More Flash, More Ram, More GPIO, More Timer Comparators, double the Hardware Interfaces, at about three times the cost haha (1.55 in 1k volume vs the 0.52 in 1k for the G2231). They come in the smallest hobbyist friendly package, 28-TSSOP, and are SBW compatible.
     
    The final line I will talk about is the MSP430F22xx line. They are basically bigger badder versions of the F21x2 line (More Ram/Flash/GPIO/Timers and a 12ch vs 10ch ADC). The F22x4 version has an a pair of opamps built in compared to the F22x2 line (20 cents more) but otherwise the same thing. The thing is that they come in a 38 pin TSSOP package. 28 pin TSSOP is the highest that I have seen in affordable dip breakout packages, so this is probably the limit for the general hobbyist unless you will etch/order custom pcbs. SBW compatible. The highest end version F227x has 32kbits of Flash, which is beyond CCS's 16kb limit. The Lower end F223x has 8kb flash, which is beyond IAR's 4kb limit. Which means you can still use them in CCS or IAR, but only up to the code limit, but you'd be paying more for using less (Unless you need to Opamps). MSPGCC has no limit.
     
    There are other SBW chips, but they are in insanely small pin packages and I won't bother going through the datasheets. As well, the planned 20pin DIP chips should be SBW and Launchpad compatible as well.
     
    Hopefully TI adds SBW as a searchable parameter for their search tool soon/eventually.
     
    TLDR:
    Launchpad/EX430 compatible lines:
    G2xxx 14-DIP/SOIC (Valueline/Launchpad Standard)
    F20xx 14-DIP/SOIC (But unless you have a bargain, the G2xxx line is cheaper/better imho)
    F21x2 28-TSSOP (2 or 3 times as good as Valueline) IAR can only use half of the highet chip's flash.
    F22xx 38-TSSOP (3 or 4 times better than Valueline) CCS can only use half of the highest chip's flash. IAR can only use half/a fourth/an eighth of the flash on the F223x/F225x/F227x respectfully.
  19. Like
    jsolarski got a reaction from bluehash in 32k crystal install and test   
    This is how to install the 32K stock crystal that comes with the MSP430 Launchpad kit
    Original post http://justinstech.org/2010/07/msp430-launchpad-dev-kit-how-too/
     
    * Supplies
    * Launch pad
    * 32KHz crystal
    * soldering iron
    * solder
    * headers
    * Bright lamp
    * electrical tape or tape like substitute
    * odds and ends (lol)(tweezers or other tool for manipulation)
     
     
    Steps
    1) open crystal packagaging and place crystal on launchpad
     
    2) more the crystal around with tweezers or other manipulation tool till the leads of the crystal line up with the solder pad
    (you may need to use a magnifying glass)
    3) tape crystal in place, and adjust so the leads are touching the pads.

    4) solder the leads to the pads*** be careful not to bridge the pads, or hold the iron on there too long.
     
    5) once you have verified that the leads are soldered, you will have to Ground the casing, there is a small pad opposite of the leads you will want to solder the casing to the pad. after that let it cool for a moment, and double check your work.
     
    6) Test- Use the WDT+ to dbl check that your crystal is functioning correctly
    IAR or CCS example code taken directly from msp430 example code

    //****************************************************************************** // MSP430F20xx Demo - LFXT1 Oscillator Fault Detection // // Description: System runs normally in LPM3 with WDT timer clocked by // 32kHz ACLK with a 1x4 second interrupt. P1.0 is normally pulsed every // second inside WDT interrupt. If an LFXT1 oscillator fault occurs, // NMI is requested forcing exit from LPM3. P1.0 is toggled rapidly by software // as long as LFXT1 oscillator fault is present. Assumed only LFXT1 as NMI // source - code does not check for other NMI sources. // ACLK = LFXT1 = 32768, MCLK = SMCLK = Default DCO // // //*External watch crystal on XIN XOUT is required for ACLK*// // // // MSP430F20xx // --------------- // /|\| XIN|- // | | | 32kHz // --|RST XOUT|- // | | // | P1.0|-->LED // // M. Buccini / L. Westlund // Texas Instruments Inc. // September 2005 // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.40A //****************************************************************************** #include volatile unsigned int i; void main(void) { WDTCTL = WDT_ADLY_1000; // WDT 1s interval timer IE1 |= WDTIE; // Enable WDT interrupt P1DIR = 0xFF; // All P1.x outputs P1OUT = 0; // All P1.x reset P2DIR = 0xFF; // All P2.x outputs P2OUT = 0; // All P2.x reset // An immedate Osc Fault will occur next IE1 |= OFIE; // Enable Osc Fault while(1) { P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR _BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/interrupt } } #pragma vector=WDT_VECTOR __interrupt void watchdog_timer (void) { _BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR) } #pragma vector=NMI_VECTOR __interrupt void nmi_ (void) { do { IFG1 &= ~OFIFG; // Clear OSCFault flag for (i = 0xFFF; i > 0; i--); // Time for flag to set P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR } while (IFG1 & OFIFG); // OSCFault flag still set? IE1 |= OFIE; // Enable Osc Fault }
     
    MSPGCC version for linux or mac users ***compiles, but is untested on MSP430***will test soon

    //****************************************************************************** // MSP430F20xx Demo - LFXT1 Oscillator Fault Detection // // Description: System runs normally in LPM3 with WDT timer clocked by // 32kHz ACLK with a 1x4 second interrupt. P1.0 is normally pulsed every // second inside WDT interrupt. If an LFXT1 oscillator fault occurs, // NMI is requested forcing exit from LPM3. P1.0 is toggled rapidly by software // as long as LFXT1 oscillator fault is present. Assumed only LFXT1 as NMI // source - code does not check for other NMI sources. // ACLK = LFXT1 = 32768, MCLK = SMCLK = Default DCO // // //*External watch crystal on XIN XOUT is required for ACLK*// // // // MSP430F20xx // --------------- // /|\| XIN|- // | | | 32kHz // --|RST XOUT|- // | | // | P1.0|-->LED // // M. Buccini / L. Westlund // Texas Instruments Inc. // September 2005 // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.40A // modified by justin solarski to work with MSPGCC 4.0 //****************************************************************************** #include // IAR & CC use #include #include //for interrupt handler volatile unsigned int i; void main(void) { WDTCTL = WDT_ADLY_1000; // WDT 1s interval timer IE1 |= WDTIE; // Enable WDT interrupt P1DIR = 0xFF; // All P1.x outputs P1OUT = 0; // All P1.x reset P2DIR = 0xFF; // All P2.x outputs P2OUT = 0; // All P2.x reset // An immedate Osc Fault will occur next IE1 |= OFIE; // Enable Osc Fault _enable_interrupt(); // enable interrupts added for mspgcc while(1) { P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR _BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/interrupt } } //#pragma vector=WDT_VECTOR removed for mspgcc interrupt(WDT_VECTOR) watchdog_timer (void) //__interrupt void watchdog_timer (void) removed for mspgcc { _BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR) } //#pragma vector=NMI_VECTOR removed for mspgcc interrupt(NMI_VECTOR) nmi_ (void) //__interrupt void nmi_ (void) removed for mspgcc { do { IFG1 &= ~OFIFG; // Clear OSCFault flag for (i = 0xFFF; i > 0; i--); // Time for flag to set P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR } while (IFG1 & OFIFG); // OSCFault flag still set? IE1 |= OFIE; // Enable Osc Fault }
     
     
    For MSPGCC you need to add #include to use the interrupt handlers (EG Interrupt(vector) Handler(void) { }
  20. Like
    jsolarski got a reaction from GeekDoc in delay function   
    This Delay function is for mspgcc, this is the one suggested by mspgcc to use instead of
    int i = 1237; while(1--); or
    int i; for (i = 0; i <1234; i++);
    mspgcc will usually remove delays like this thinking it is a wast of space.
     
    mspgcc suggest to use an inline function like this example taken from the mspgcc user guide.

    static void __inline__ msp_delay(register unsigned int n) { __asm__ __volatile__( " 1: \n" " dec %[n] \n" " jne 1b \n" : [n] "+r"(n)); }
    call this function when ever you need to do a short delay(or long one lol)
    example

    //"your code" msp_delay(15); //delay //"your code"
     
    you may be able to use this in CCS or IAR but I'm not sure, since I do not have the windows box to run those programs.
×
×
  • Create New...