I'm want to use an external low frequency crystal (32kHz) for the timer in my MSP430G2553 and the internal oscillator at 8MHz, but in the datasheet I can't see how I should use the external crystal for the timer. As there only appears to be one pin(TACLK). So how would the design for the oscillator look?
To use an external 32.768 KHz crystal with the MSP430G2553, the crystal needs to be soldered between the Xin and Xout pins of the microcontroller. In the DIP package, those are pins 18 and 19. No additional components are required for this.
TA0CLK has nothing to do with this crystal's connection, please see the pin descriptions in the datasheet.
See this schematic of the MSP430 Launchpad Target Microcontroller section:
You can see the two 0 Ohm resistors on the pins 18 and 19 - the crystal attaches between them.
- Adding a crystal prevents those pins from being used as GPIO Pin 2.6 / TimerA TA0.1 (the Xin pin's other functions) and GPIO Pin 2.7 (the Xout pin's other function.
- Instead of crystal, a digital clock from an oscillator can also be supplied to Xin in bypass mode.
- For crystals of frequency higher than the 32.768 KHz crystal, appropriately sized load capacitors are required in addition. See the relevant part-specific datasheet for this.
Once the 32.768 KHz watch crystal is connected to the MSP430, the following notes are handy to confirm that the crystal is operational, and of course to use the crystal going forward.
- The crystal on XIN / XOUT is used as ACLK. Conversely, for using ACLK, a crystal must be connected between XIN and XOUT.
- If the implementation is on an MSP430 Launchpad board, note that crystal diagnostic code is provided in Justin's Tech Blog - the gold standard that pretty much everyone followed in the early days of the Launchpad.
- Other such walk-throughs are in NJC's Launchpad Blog, and in the TI "Getting Started with the MSP430 Launchpad" document, in the "Optional Lab Exercise – Crystal Oscillator" section.
- The internal (on-chip) matching capacitance needs to be set for the crystal to work: Set BCSCTL3 (Basic Clock System Control 3),
BCSCTL3 |= XCAP_3;for the 12.5 pF watch crystal provided with the Launchpad.
- Detailed information on using Low Frequency Crystals is provided in this TI document.
- An excellent, step by step explanation and verification code is provided in this blog.
- Most important: Code using LF crystal ACLK does not function as expected while stepping through in debug mode, you have to run the code in "Run" mode for the various diagnostic code fragments mentioned above to work. This quirk is apparently not documented anywhere, I spent a fair bit of time removing and resoldering the crystal on my first launchpad, assuming a failure, till I figured this out.
Parts like microcontrollers are often too complex to fit all the data about them into just a datasheet. For your part there's also a MSP430x2xx Family User's Guide (Rev. I).
In that document on page 366, you'll find "The timer clock can be sourced from ACLK, SMCLK, or externally via TACLK or INCLK."
And, on page 278,
Three clock signals are available from the basic clock module+: • ACLK: Auxiliary clock. ACLK is software selectable as LFXT1CLK or VLOCLK. ACLK is divided by 1, 2, 4, or 8. ACLK is software selectable for individual peripheral modules. • MCLK: Master clock. ... • SMCLK: Sub-main clock. SMCLK is software selectable as LFXT1CLK, VLOCLK, XT2CLK (if available on-chip), or DCOCLK. SMCLK is divided by 1, 2, 4, or 8. SMCLK is software selectable for individual peripheral modules.
So you need to select either ACLK or SMCLK as the clock source for your timer, and then select the crystal source ("LFXT1CLK") as the source for your ACLK or SMCLK. The choice between ACLK and SMCLK probably comes down to which power-down modes you need to use, and whether you need to keep the timer active during power down.
Building an external oscillator to feed TACLK will likely use substantially more power than using the the uC's own crystal circuit.