• Category Archives programing
  • New Toys, Bigger msp430 and a stellaris launchpad

    New toys came in the other day from the 43oh.com store.
    I ordered 2x msp430f5510 USB dev boards, created By Robg , also I received a Stellaris Launchpad (on loan till mine come in) .


    These are Nice little boards, and will work great for any one trying with a Launchpad and would like to try some of the bigger flagships. These are very easy to solder and get up and running.




    To program them, all I did was connect the RST, TST, Vcc, Gnd between the launchpad and the dev board. Ran mspdebug, and it worked on the first try.

    Sorry for the poor screen shot.





    As of right now, I am working on porting msp430USBDev API from TI. It is both IAR and CCS code, and both will not work out of the box with mspgcc.

    But with some minor changes I think I can get it to work.

    There is a Port of the devpack, but It has an autogen.sh file that makes the makefile and links things automatically…… and in general I had issues with it, it compiled correctly but did not run on my 5510, even after I changed the minimal configuration options it gave.
    Now I don’t know what the guy changed or what he did to get it to work other then some linker options about the usb buffer/ram.

    I will give an update on this as soon as I get it to work.


  • MSP430 – different Interrupts for different compilers

    The different compilers out there for msp430 chips and Launchpad have different syntax for each one –

    Hopefully this post will help you find out which one you need.

    (all examples are for chip msp430g2231, just substitute your chip that you are working with)

    First – CSS/IAR — TI officially supported compilers/IDEs

    #pragma vector=TIMERA1_VECTOR
    __interrupt void Timer_A1(void)    { //ISR code




    second – mspgcc4 – IDE of your choice

    Makefile — must have this option to compile correctly to chip -mmcu=msp430x2231 –most chips are supported but you will have to find the correct one for yours.

    Main.c file or main project file

    you must include these

    #include <msp430g2231.h>
    #include <signal.h>

    and then the syntax for your ISR

    interrupt(TIMERA0_VECTOR) Timer_A (void) {  //code goes here}


    Third — Uniarch mspgcc – Newest compiler – replacement for mspgcc4


    makefile– -mmcu=msp430g2231   you must use the one specific for your chip and should not include an x in the mmcu option since that is for the depreciated mspgcc4

    inlcude these header files

    #include <msp430.h>
    #include <legacymsp430.h>

    ISR syntax

    interrupt(TIMERA0_VECTOR) Timer_A (void)
    {  //code goes here}


    Fourth way– Offiacial uniarch mspgcc ISR syntax

    makefile – same as before

    no extra includes needed, just the msp430.h or specific chip header

    void Timer_A(void){ //code goes here }

    Source link


    This is not complete, I am waiting for an answer on what the syntax should be for uniarch branch of mspgcc for interrupts. So far my testing has only allowed using interrupts using the lgacymsp430.h header. Once I get an answer I will update this post.

    update —

    so far this alternative works – (works == compiles with no errors)

    The syntax for declaring an interrupt with gcc is (as far as I learnt so far)
    void irq_handler_for_vector(void);
    with VECOR_NAME the name of the IRQ vector. example:
    void usbRxISR(void){ 
    Thank you Matthias - for this alternative.

  • MSP430 Uniarch mspgcc or mspgcc4?

    You are probably asking yourself which compiler for your launchpad/msp430, you should use. Me personally, I don’t really care which one works Better, I just need one to compile for my launchpad and supports the chips I use.

    some similarities  —

    Both create files for your msp430 chip,

    both are compiled  with GCC 4.x+

    Both use libc for the msp430.

    They pretty much fill the same function.


    Now some of the major differences, mspgcc4 is stable and  can be used with production code, Uniarch is still being developed and is changing a lot still. mspgcc4 supports most of the chips for msp430 except the very newest (since it is hard to add newer chips with out rebuilding and adding a lot of code).  Uniarch is trying to make adding chip support as easy as possible, and unifying all the branches of mspgcc. Even coding is slightly different, interrupts are coded different and even the headers you use may be different(FYI).


    So which one should I choose?

    Well that is a tough question, what are your goals?

    are you trying to get one just up and running or do you need support for the newest chips? — Have you compiled programs from source or are you new to linux?

    Will you give up after you get an error or will you work through it and figure it out?


    Well if you need just something up and running just to be able to compile a few programs for your launch pad , I would suggest using mspgcc4 , using the build script or using the pre-built binaries. pre- built binaries, to install, you just add a folder to usr/local/ and call it mspgcc4 and unpack your binaries in there and that it.  The build script is pretty self explanatory, and it compiles everything from source . I have used it multiple times and works as long as you have all the dependencies. IE(ncurses-dev, cvs, lidreadline-dev etc…)

    A very simple way to get it up and running –


    Now if you want access to the New uniarch mspgcc, that supports the new chips like msp430g2452 or others. you will need to go the long and hard route of patching compiling linking and more compiling lol. but there are some great directions to do it. Here (Thank you sergio). But it is not for the faint of heart….lol /JK

    Continue reading  Post ID 1092

  • MSP430: Custom calibration for DCO

    While using the launchpad and Value line chips, I was a little Disappointed in lack of calibration data and no way to reliably change the default settings. So I started flashing the DCO calibrations data –> original post http://www.43oh.com/forum/viewtopic.php?f=10&t=239&hilit=calibration
    Now the default 1 8 12 and 16 MHZ settings are fine but what if you wanted a bunch of chips to run on 3MHz or 500KHz. Are you will to try and figure out the RSEL and MOD and DCO bits and start randomly flipping testing settings? To me this sounds like a long and boring process and I don’t have the time to test and try and get 2MHz, or what if I need 10MHz , my scope doesn’t even come close to that 🙁 .

    So I decided to modify the TI DCO flash calibration code from TIs examples, these changes allow me to set the default and the other calibration data to the settings I want.
    The few changes I made are,

    • Added Xcap setting to BCSCTL3 to make internal cap 12.5pF
    • Added custom constant to replace 1MHz default(244), – new one is for 2MHz

    no other changes made to the code.



    Now there is a few things to remember, This code will re-write over TI calibrated constants if you have An F series (IE everything but value line G series) chips. Or it will Write the calibration to the G line chips – which are not calibrated when you get them except the 1MHz default.



    // Custom DCO settings- based on TI code example
    // MSP430F20xx Demo - DCO Calibration Constants Programmer
    // MSP430F20xx
    // ---------------
    // /|| XIN|-
    // | | | 32kHz
    // --|RST XOUT|-
    // | |
    // | P1.0|--> LED
    // | P1.4|--> SMLCK = target DCO
    // Orignal Code By
    // A. Dannenberg
    // Texas Instruments Inc.
    // May 2007
    // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.42A
    /*Flash Custom DCO settings, This will replace The default 1MHz */
    /* to use
    //Custom calibration
    BCSCTL1 = CALBC1_1MHZ; // Set range
    DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
    //ACLK = LFXT1/8 = 32768/8, MCLK = SMCLK = target DCO
    //* External watch crystal installed on XIN XOUT is required for ACLK *//
    #include "msp430f2013.h"
    #define DELTA_CUSTOM 489 // 489 x 4096Hz = 2002944Hz or 2.02MHz
    #define DELTA_8MHZ 1953 // 1953 x 4096Hz = 7.99MHz
    #define DELTA_12MHZ 2930 // 2930 x 4096Hz = 12.00MHz
    #define DELTA_16MHZ 3906 // 3906 x 4096Hz = 15.99MHz
    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 Delta);
    void main(void)
    for (i = 0; i < 0xfffe; i++); // Delay for XTAL stabilization P1OUT = 0x00; // Clear P1 output latches P1SEL = 0x10; // P1.4 SMCLK output P1DIR = 0x11; // P1.0,4 output BCSCTL3 = XCAP_3; // Set internal cap to 12.5 j = 0; // Reset pointer Set_DCO(DELTA_16MHZ); // Set DCO and obtain constants CAL_DATA[j++] = DCOCTL; CAL_DATA[j++] = BCSCTL1; Set_DCO(DELTA_12MHZ); // Set DCO and obtain constants CAL_DATA[j++] = DCOCTL; CAL_DATA[j++] = BCSCTL1; Set_DCO(DELTA_8MHZ); // Set DCO and obtain constants CAL_DATA[j++] = DCOCTL; CAL_DATA[j++] = BCSCTL1; Set_DCO(DELTA_CUSTOM); // 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 while (1) { P1OUT ^= 0x01; // Toggle LED for (i = 0; i < 0x4000; i++); // SW Delay } } void Set_DCO(unsigned int Delta) // Set DCO to selected frequency { unsigned int Compare, Oldcapture = 0; BCSCTL1 |= DIVA_3; // ACLK = LFXT1CLK/8 TACCTL0 = CM_1 + CCIS_1 + CAP; // CAP, ACLK TACTL = TASSEL_2 + MC_2 + TACLR; // SMCLK, cont-mode, clear while (1) { while (!(CCIFG & TACCTL0)); // Wait until capture occured TACCTL0 &= ~CCIFG; // Capture occured, clear flag Compare = TACCR0; // Get current captured SMCLK Compare = Compare - Oldcapture; // SMCLK difference Oldcapture = TACCR0; // Save current captured SMCLK if (Delta == Compare) break; // If equal, leave "while(1)" else if (Delta < Compare) { DCOCTL--; // DCO is too fast, slow it down if (DCOCTL == 0xFF) // Did DCO roll under? if (BCSCTL1 & 0x0f) BCSCTL1--; // Select lower RSEL } else { DCOCTL++; // DCO is too slow, speed it up if (DCOCTL == 0x00) // Did DCO roll over? if ((BCSCTL1 & 0x0f) != 0x0f) BCSCTL1++; // Sel higher RSEL } } TACCTL0 = 0; // Stop TACCR0 TACTL = 0; // Stop Timer_A BCSCTL1 &= ~DIVA_3; // ACLK = LFXT1CLK }

    So you want a your own custom frequency, now the easiest way to do this is take your target clk speed and divide it by 4096. which 4096 is 32KHz clock divided by 8. For my 2MHz calculation I did 489 x 4096Hz = 2002944Hz or 2.02MHz
    you division will get you close to the number you will need, round up or down according to your frequency. I choose to go a little over/ round up.

    Remember the Faster your clock, the farther you will be away from your target
    example - 488 x 4096 = 1,998,848
    489 x 4096 = 2,002,944
    difference 4,096

    Its not too bad but if you are going for a specific CLK speed you may need to try a different method like an oscilloscope, and manually changing the DCO, RSEL, MOD bits .

    FYI there is a test program included in the zip file to test your new calibration data.

  • MSP430: SDA16? what would I ever use that for.

    SDA16 is a 16Bit sigma-delta ADC, and is one of the options for MSP430 line of chips. But then you ask, doesn’t the mps430 have a ADC with 10 to 12 bits? Yes it does but the SDA is a different beast all together, with more settings and registers. For more information on how it works please feel free to read some application notes and the Wiki. I personally cant answer how or why you need to send your oversampled , comb filtered, decimated and modulated signal to get 16 Bit resolution.

    application notes on SDADC

    WIKI on how its done.

    But lets get started by going over some of the Registers you will need to setup and or modify.

    SD16CTL – control register
    controls Clock source, power mode, clock divider, V ref selection, overflow interrupt.

    SD16CCTL0 – channel register
    Controls Buffer mode(no buffer in F2013), Bipolar or unipolar, conversion mode over
    sampling and LSBACC enable, conversion interrupt, data format, interrupt flag and
    conversion start

    SD16INCTL0 – input control
    Sampling rate, preamplifier gain, differential pair select

    SD16AE – analog enable
    Selects external Analog input

    SD16IV – Interrupt vector – self explanatory

    SD16MEM0 – conversion memory – where your conversion will end up when sda16 is finished with conversion.

    ** all these registers mentioned are reset with PUC

    Yes I know it looks like a lot, but it really doesn’t take that much to start getting readings .
    So the first thing you need to do is select your differential pair/ Pins you will be using. ** you will have to use the Data sheet to pick your Pairs, and remember if you are using an external VREF P1.3 will be used on the F2013 so that leaves open 7 other pairs to select from.
    Continue reading  Post ID 1092

  • MSP430: VLO and You!!

    So what is the VLO? The VLO is the very low- freq Oscillator, low power and low frequency(12KHz). So how does this change things, well now you can source your clocks from the DCO or the VLO instead of the 32Khz watch crystal. …….and now your asking yourself “Do I really need another clock source?” I say “yes!!”

    Now what can you do or how can i use the VLO? Its super easy to setup the VLO. In the Family user guide for the MSP430, Basic Clock Module+ will be your reference to set up the VLO.
    Registers that you will be concerned about are BCSCTL2, BCSCTL3 and the special functions registers.


    • BCSCTL3 needs LFXT1S_2 to be set

    BCSCTL3 |= LFXT1S_2;                      // LFXT1 = VLO

    • BCSCTL2 needs to be set

    BCSCTL2 |= SELM_3 + SELS;                 // SMCLK  = MCLK = VLO = 12Khz

    • Clear OSC fault flag

    IFG1 &= ~OFIFG;                           // Clear OSCFault flag

    • Turn off DCO if not used

    _BIS_SR(SCG1 + SCG0);                // Stop DCO


    And that is all you need to do to setup your msp430 to use the VLO for SMCLK, AMCLK and MCLK @ 12KHz.  So now you need more control. so here are your VLO options

    BCSCTL1 –  controls XTS(not avalable on msp430x20xx), Divider for ACLK, and DCO range select.

    • DIVAx  – divide ACLK source by 1,2,4,8 or 00, 01, 10, 11(bit settings). Pretty much this will divide your Clock source by 1 – 8. This setting is just for ACLK which will be the crystal or VLO. (this only affects ACLK)
    • XTS, XT2OFF, and RSELx are not used for VLO but may be a good idea to read up on what they do.



    BCSCTL2  – controls MCLK divider, SMCLK divider MCLK and SMCLK clock source, each one is configurable.

    • SELMx – selects MCLK clock source, your choices are DCOCLK or LFXT1CLK/VLOCLK  just remember you cant use the VLO and the crystal
    • DIVMx – MCLK divider, divides the clock source by given amount, 1,2,4,8
    • SELS – select SMCLK source  DCOCLK or LFXT1CLK/VLOCLK
    • DIVSx – look another Divider, this one is for SMCLK
    • DCOR- not used – sets DCO resister to internal or external


    BCSCTL3 – XT and LFXT setting, only one setting is really used here.

    • LFXT1Sx – source of LFXT1,  00(0) for 32KHz crystal and  10(2) for VLO instead of the crystal
    • XT2Sx, XCAPx, XT2OF, LFXT1OF are not set or used for the VLO



    So now you have a basic understanding on how to setup your VLO, now let me give you a quick  VLO test


    /* VLO clock as main source instead of the DCO */
    #include  <msp430x20x3.h>
    void main(void)
    WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
    BCSCTL3 |= LFXT1S_2;                      // LFXT1 = VLO
    IFG1 &= ~OFIFG;                           // Clear OSCFault flag
    __bis_SR_register(SCG1 + SCG0);           // Stop DCO
    BCSCTL2 |= SELM_3;               // MCLK = LFXT1
    P1DIR |= 0x01;                            // Set P1.0 to output direction
    for (;;)
    volatile unsigned int i;
    P1OUT ^= 0x01;                          // Toggle P1.0 using exclusive-OR
    i = 50000;                              // Delay
    do (i--);
    while (i != 0);

    code for use with mspgcc


    Now that we have the basics down on the VLO, what are some of the uses for it? Really low power clock, or a 3rd clock source that’s a different frequency then the main, really slow ADC conversions, odd SDA16 filter frequency, a low frequency tone generator.


    What other uses can you find? Let me know in the comments 🙂

  • Ubuntu 10.04, 10.10, 11.04 The bane of my existence!!

    I have been an avid fan of ubuntu and I still am, but for newer hardware only. Recently I had to upgrade to 9.10 and then to 10.x. let start with my first issue in 9.10  and we will go from there. In 9.10 my sound and video would not play. this was caused by pulse audio and also not working together or something like that, personally i could not find the exact issue or cause, which made this issue very hard to fix…. but a fix was found….i will go over that in a min or two lol.

    Next issue was the keyboard and mouse locking up on ubuntu 10.04 and higher, this is a big pain, because once they lock up, both the PS2 keyboard and mouse freeze, and so do the usb keyboard and mouse. This makes is very hard to find a fix since i may have 2 secs of the mouse moving or i might get 5 mins, either way it locks and i have to reboot, and thats not a guaranteed fix.

    So lets start on how i fixed the 9.10, 10.04, 10.11 with an audio issue. The symptoms are choppy music play and then it cuts out, log file filled with “karmic pulseaudio [1653]: ratelimit.c: 2 events supressed” also video usually stops or wont play as well…… to Help most of you out, i have tried everything from recompiling the kernel, to installing from source, compiling pulse from source, changing alsa drivers, changing the scheduling, using every google fix there is……not even launchpad couldnt give me any info. There are bugs listed but no real fixes or workarounds…until now lol.  if you have applications that use pulseaudio ( im not sure what depends on it) this may not be a good workaround.


    Unistall Pulse Audio!!! (Thanks Kevix from the 43oh IRC room/forums!!) He stated that most programs still use alsa and dont need pulseaudio.

    as soon as i did that, my sound worked as well as my video, even the system alerts could be heard!!

    this worked for me, on my audiology and on board sound card…..I do not know the extent of pulse integration with ubuntu desktop so try at your own risk and feel free to let me know how it worked out for you. 🙂

    on to my next issue Ubuntu 10.4-11.04 Keyboard and mouse do not work/ freeze after a few min.

    This issue has been going on since i had tried 10.04 a little after the initial release, I haven’t tried nearly as much as i had worked on the other issue, but this one is inherently very hard to pinpoint for me. no log messages or errors, even on verbose…….tried combination of ps2 and usb with no luck at all.  I even tried reinstalling Dbus and Hal with no luck ….. and this is where i am stuck.

    My choices are continue on working on the issue and be down a PC (this is my main PC used for everything) or find a distro that works with my older PC, both require a decent amount of work to get it all going, including all the programs i have compiled from source.

    So any ideas ? any thoughts? another distro i could try? im willing to try almost anything to get my PC up and running so i can watch youtube on my tv!!

    PC specs

    P4 2 x cores with asus motherboard

    ATI 9600/128mb

    ram 1.2Gb

    nothing too special lol

    Leave some comments 🙂


  • MSP430 RGB V0.1

    A different take on how to create a PWM signal. I decided to go the interrupt route using the WDT+ peripheral. I did this by setting it to the interval timer and putting all my counters and logic within the interrupt. The funny thing is  i have read that you shouldn’t put too much code into your interrupt, or something bad will happen.

    the resistors on the left, are 100 ohm resistors and the one on the right is a 470 ohm resistor to limit current for the RGB LED. connections on the uC that are used are pins 1.3, 1.4, 1.5 i have not decided which pins are what color, i will decide that on my final build.

    The test code will be improved this is just the compile and see if it works.- The best part , the code works lol .

    so let me know what you think on creating PWM with the interval timer instead of timer A.

    #include <msp430x20x2.h>
    #include <signal.h> //add for interrupt
    #define UP 0x00
    #define DOWN 0x01
    volatile  int millsecs = 0;
    volatile  int counter2 = 0;
    volatile  int led_red = 0;
    volatile  int led_green = 199;
    volatile  int led_blue = 199;
    volatile  int dir = UP;
    void main(void)
    WDTCTL = WDT_MDLY_0_064;
    P1DIR |= BIT5 + BIT4 + BIT3;
    P1OUT |= BIT5 + BIT4 + BIT3;
    IE1 |= WDTIE;
    }//end main
    interrupt(WDT_VECTOR) watchdog_timer(void)
    if (millsecs == 200) { millsecs= 0; P1OUT |= BIT0 + BIT6; ++counter2; }
    if (millsecs == led_red ) { P1OUT ^= BIT3; }
    if (millsecs == led_green) { P1OUT ^= BIT4; }
    if (millsecs == led_blue ) { P1OUT ^= BIT5; }
    if (counter2 == 25 ) { counter2 =0;
    switch (dir){
    case UP: ++led_red; --led_green; --led_blue;
    if (led_red == 199) {dir = DOWN;}
    case DOWN: --led_red; ++led_green; ++led_blue;
    if (led_red == 0) {dir = UP;}
    }//end switch
    }//end if
    }//end interrupt

    To change the Period length – change the 200 value to the period you want, you can also change it by setting the WDT interval to different intervals to change the period.
    to change the Duty cycle, change the led_[color] variable to anything between 0 and period length

    I am still working on trying to get it to cycle through all colors, and fade better when led_[color] is close to 0
    by far this project is not done, the board will be soldered up and pics will be presented. The end result should be code for WDT PWM, which could be used for servos, LEDs, or possibly communication, and i will have my flower pot back!

  • MSP430: what doesnt work…….

    This will be an on going post that will be constantly updated on what doesn’t work when coding for the msp430…….yes this will feature my failings lol.
    so for the first Failure……

    Project: RGB led fade to different colors with a ~4 hour timer
    This fail is a test program that i had created to test the software PWM using WDT+ and interrupts.
    CCFLAGS = -mendup-at=main
    -mendup-at=”function”—when main ends, it usually goes to stop program execution, but you can make it jump back to main when main exits. pretty much sets it up as a never ending loop. great if main is supposed to never exit or return.

    #include<signal.h> //interrupt SR
    volatile unsigned int timer1 = 0;
    void main(void) {
    P1DIR |= BIT0+BIT6;
    IE1 |= WDTIE;
    if (timer1==126) {
    timer1 = 0;
    P1OUT ^= BIT6;
    }//end if
    }//end main
    interrupt(WDT_VECTOR) watch_dog_timer(void)
    P1DIR ^= BIT0;
    } //end interrupt

    what it was supposed to do is cycle through the program, when the WDT causes an interrupt the timer is supposed to increment
    then once the timer reaches 126 it resets and toggles P1.6(green LED on launchpad)

    what it did is loop through, never servicing an interrupt, and looped with out doing anything……well almost nothing, timer1 never incremented but the main loop did compare timer1 to 126.
    for some reason the interrupt never gets serviced because it goes back to main and clears the WDT timer count, so then it runs it runs so quick that the interrupt that’s sitting there clears when it goes back to main…..
    Cause: my theory says my code maybe too short for it to call the interrupt fully.
    When i step through it the interrupt flags never get called, and before you know it the whole thing starts over again.
    Fix: none as of yet still testing

    Continue reading  Post ID 1092