AaronInSpace 4 Posted January 30, 2012 Share Posted January 30, 2012 I've been working on a high-altitude balloon for the last couple months. It is controlled by an MSP430-F2619. I wish I had a schematic to show you but I didn't make one and its complicated enough now that I'd rather just float this question out there without one and if we can't say without seeing them, oh well. So, here it goes! There is a 5 MHz digital oscillator driving LFXT1 through XOUT (pin 9 on the 64-pin PM package). Here's my clock and initialization code: void init_clocks_and_io(void) { volatile u32 i; WDTCTL = WDTPW + WDTHOLD; // Stop WDT // Set all unused pins to output to prevent floating inputs P1DIR |= BIT1; P1DIR |= BIT2; P1DIR |= BIT3; P1DIR |= BIT4; P1DIR |= BIT5; P1DIR |= BIT6; P1DIR |= BIT7; P2DIR |= BIT0; P2DIR |= BIT1; P2DIR |= BIT2; P2DIR |= BIT3; P2DIR |= BIT4; P2DIR |= BIT5; P2DIR |= BIT6; P2DIR |= BIT7; P3DIR |= BIT0; P3DIR |= BIT3; P4DIR |= BIT0; P4DIR |= BIT1; P4DIR |= BIT2; P4DIR |= BIT4; P4DIR |= BIT5; P4DIR |= BIT6; P4DIR |= BIT7; P5DIR |= BIT0; P5DIR |= BIT1; P5DIR |= BIT2; P5DIR |= BIT3; P5DIR |= BIT4; P5DIR |= BIT5; P5DIR |= BIT6; P5DIR |= BIT7; BCSCTL1 = 0x87 | XTS; // Default reset + // XTS = high-freq mode BCSCTL2 = 0x00; // Default reset BCSCTL3 = 0x30; // Default reset + // Turn oscillator capacitor to ~1 pF + LFXT1S_3 = 11 digital input do { IFG1 &= ~OFIFG; // Clear OSCFault flag for (i = 0xFFF; i > 0; i--) // Time for flag to set { __delay_cycles(1); } } while (IFG1 & OFIFG); IFG1 &= ~OFIFG; // Clear OSCFault flag BCSCTL2 = 0xC0; // SELS = DCO, SELM = 5MHz(MCLK -> 5 MHz) init_UARTA0(); init_UARTA1(); __enable_interrupt(); } /* init_clocks_and_io() */ In this way it works. But if at the 4th to last line, I make that BSCTL2 = 0xC8; SELS ->5MHz crystal on LFXT1, then this gets very unstable. If I just do a UART spam test (shown below), I see random bad characters. I also see SMCLK being disturbed if I scope its output on pin 5.5. The crystal, MCLK, or ACLK on the other hand show no sign of the disturbance (which appears as a jitter in the position of the square wave when viewed on an o-scope): void main(void) { static int i; i = 0x30; init_clocks_and_io(); while (1) { printf("%c", i++); __delay_cycles(5000); if (i > 0x39) { i = 0x30; } } } I've also tried replacing the chip, replacing the crystal, fixing its voltage divider (which had V high below the minimum for 1 logic) etc. Now if I just take my code and run UARTS off of ACLK and just ignore SMCLK and set it to the DCO, using this same crystal as the source for everything, my code runs perfectly. No crashes, no UART errors, nothing! What am I missing or did I find a flaw in the chip? Quote Link to post Share on other sites
SugarAddict 227 Posted January 30, 2012 Share Posted January 30, 2012 Is 0xC8 = XTS = 1, LFXT1Sx = 2, XCAPx = 0 ? Quote Link to post Share on other sites
AaronInSpace 4 Posted January 30, 2012 Author Share Posted January 30, 2012 I appologize for the lack of commenting on those lines. I was worried that my IDE was doing weird things with bit logic and so just assigned values instead of ORing in constants. I'll explain my expectations of what I have set in the registers. # This sets XT2OFF to 1 making sure XT2 is not running. The "7" sets RSELx to 7 which is a range select for the DCO BCSCTL1 = 0x87 | XTS; // Default reset + // XTS = high-freq mode # This sets MCLK to DCOCLK with a divider of 1, sets SMCLK to DCOCLK with a divider of 1 and sets the DCO resistor to internal BCSCTL2 = 0x00; // Default reset # This sets XT2S to low speeds (its not used as per above), sets LFXT1S to a digital external 0.4 to 16-MHz clock source # (assuming XTS is 1 which it is as set above), and XCAPx to 0 (~1 pF oscillator capacitor), and ignores the oscillator fault flags. BCSCTL3 = 0x30; // Default reset + // Turn oscillator capacitor to ~1 pF + LFXT1S_3 = 11 digital input When I set BCSCTL2 to 0xC8 this should do the following # SELMx = 11, LFXT1CLK or VLOCLK with a divider of 1; the "8" sets SELSx to XT2CLK when XT2 oscillator present (which it is not in my understanding of this phrase; I do not have one installed though the chip allows for one). LFXT1CLK or VLOCLK when XT2 oscillator not present (so it should do this setting SMCLK to LFXT1CLK). Hope that clears it up. Thanks! Quote Link to post Share on other sites
AaronInSpace 4 Posted February 6, 2012 Author Share Posted February 6, 2012 Bump Quote Link to post Share on other sites
oPossum 1,083 Posted February 6, 2012 Share Posted February 6, 2012 There is a 5 MHz digital oscillator driving LFXT1 through XOUT (pin 9 on the 64-pin PM package). I think that should be XIN (pin 8). I can't find any specific statement in the MSP430 spec sheets that says that, but it is typical for connection of an oscillator module to a microcontroller. bluehash and AaronInSpace 2 Quote Link to post Share on other sites
AaronInSpace 4 Posted February 6, 2012 Author Share Posted February 6, 2012 Good catch. Pardon me! It is in fact pin 8 (XIN) which the oscillator is attached to with these issues. I keep getting mixed up on that point since you can imagine XIN being the input to the crystal (WHICH IT IS NOT!) Still limping along. Anyone notice anything else? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.