title: MSP430 clock problems after reset
body: <p>I use the following routine to configure the clock of my MSP430 (msp430g2231) microcontroller:</p>
  
  <pre><code>void configure_clock(void) {
  if (CALBC1_1MHZ == 0xFF || CALDCO_1MHZ == 0xFF) { // Checks the clock constants
          while(TRUE); // If callibration constants are erased, TRAP!
      }
  
      BCSCTL1 |= CALBC1_1MHZ; // Sets DCO range
      DCOCTL |= CALDCO_1MHZ; // Set DCO step and modulation
  
      BCSCTL1 &amp;= ~(XTS | XT2OFF); // Disables XT2 and sets low frequency mode
      BCSCTL3 |= (LFXT1S_0 | XCAP_3); // Selects LFXT1 crystal with 12,5pF
  
      do {
          IFG1 &amp;= ~OFIFG;
          __delay_cycles(1000);
      } while (IFG1 &amp; OFIFG); // Waits until crystal stabilizes
  
      BCSCTL2 |= (SELM_2 | SELS); // Selects SMCLK and MCLK from LFXT1CLK
  }
  </code></pre>
  
  <p>The problem is that the first time the code runs (just after powering up the microcontroller) everything works as expected and I get 32768 kHz clock. But if I press the reset button on the board (MSP430 Launchpad) the clock does not seem to work correctly, the code executes much slowly (like 10 times or so). Any ideas on the clock configuration?</p>
  
  <p>Thanks!</p>
  
  <p>Pere</p>