energia / Energia

Fork of Arduino for the Texas Instruments LaunchPad's
http://energia.nu
Other
794 stars 672 forks source link

Energia prevents use of external 32.768khz crystal #130

Closed elliotmatson closed 11 years ago

elliotmatson commented 11 years ago

I have code in CCS that uses the external crystal to toggle an LED once per second using the external crystal. The same code (with necessary modifications) in Energia doesn't use the external crystal and instead used the internal 12khz oscillator. I am using a 2553

CCS Code: ---_--_--_-_---_--_-_---_--_-_---_--_-_---_-_--_--_ /**

unsigned int currentMinutes, currentSeconds;

void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT

BCSCTL1 |= DIVA_3;              // ACLK/8
BCSCTL3 |= XCAP_3;              //12.5pF cap- setting for 32768Hz crystal

P1DIR |= BIT0;                  // set P1.0 (LED1) as output
P1OUT |= BIT0;                  // P1.0 low

currentMinutes = 0;
currentSeconds = 0;

CCTL0 = CCIE;                   // CCR0 interrupt enabled
CCR0 = 512;                 // 512 -> 1 sec, 30720 -> 1 min
TACTL = TASSEL_1 + ID_3 + MC_1;         // ACLK, /8, upmode

_BIS_SR(LPM3_bits + GIE);           // Enter LPM3 w/ interrupt

}

// Timer A0 interrupt service routine

pragma vector=TIMER0_A0_VECTOR

__interrupt void Timer_A (void) { P1OUT ^= BIT0; // Toggle LED }

---_--_--_-_---_--_-_---_--_-_---_--_-_----

Energia code: ---_--_--_-_---_--_-_---_--_-_---_--_-_---- /**

void setup() {}

void loop() { WDTCTL = WDTPW + WDTHOLD; // Stop WDT

BCSCTL1 |= DIVA_3;              // ACLK/8
BCSCTL3 |= XCAP_3;              //12.5pF cap- setting for 32768Hz crystal

P1DIR |= BIT0;                  // set P1.0 (LED1) as output
P1OUT |= BIT0;                  // P1.0 low

CCTL0 = CCIE;                   // CCR0 interrupt enabled
CCR0 = 512;                 // 512 -> 1 sec, 30720 -> 1 min
TACTL = TASSEL_1 + ID_3 + MC_1;         // ACLK, /8, upmode

_BIS_SR(LPM3_bits + GIE);           // Enter LPM3 w/ interrupt

}

pragma vector=TIMER0_A0_VECTOR

__interrupt void Timer_A (void) { P1OUT ^= BIT0; // Toggle LED }

---_--_--_-_---_--_-_---_--_-_---_--_-_----

robertinant commented 11 years ago

I gave this some thought and since most users will not have an external XTAL hooked up I am going to leave it as it is. If external XTAL needs to be used then it will have to be enabled in code (e.g. P2.6/P2.7 need to be set to XTAL and ACLOCK needs to be set to external XTAL). I have just pushed a commit that sets P2.6/P2.7 default to GPIO.