I’m having trouble setting up the MSP430F5437 to run from a 16MHz master clock. (It’s my first time working on MSP programming from scratch, and we havent used the 500 series chips before.)
I have a 16MHz crystal connected to XT1 with external caps. Other than that, there are no other external components being used in the code yet. We also have a 4MHz crystal available but need the master clock to run at 16MHz to write to an SRAM chip fast enough. Are there some obvious mistakes in my coding?
I got the SetVCoreUp function from the MSP430x5xx User guide although what’s curious to me here is that the sample TI code for a 12MHz DCO does not change the core voltage but the user guide says you must change the core voltage. (The datasheet shows 16MHz in the third range and 12MHz in the second voltage range)
With the following code, it gets stuck in the loop waiting for XT1 to stabilize. OFIFG keeps being set due to the DCOFFG in UCSCTL7 being set. Furthermore, this is caused by the DCO bits in UCSCTL0 are set to 0x31.
Any Help would be much appreciated,
Thanks
main.c :
#include “msp430x54x.h”
void SetVCoreUp (unsigned int level)
{
// Open PMM registers for write access
PMMCTL0_H = 0xA5;
// Set SVS/SVM high side new level
SVSMHCTL = SVSHE + SVSHRVL0 * level + SVMHE + SVSMHRRL0 * level;
// Set SVM low side to new level
SVSMLCTL = SVSLE + SVMLE + SVSMLRRL0 * level;
// Wait till SVM is settled
while ((PMMIFG & SVSMLDLYIFG) == 0);
// Clear already set flags
PMMIFG &= ~(SVMLVLRIFG + SVMLIFG);
// Set VCore to new level
PMMCTL0_L = PMMCOREV0 * level;
// Wait till new level reached
if ((PMMIFG & SVMLIFG))
while ((PMMIFG & SVMLVLRIFG) == 0);
// Set SVS/SVM low side to new level
SVSMLCTL = SVSLE + SVSLRVL0 * level + SVMLE + SVSMLRRL0 * level;
// Lock PMM registers for write access
PMMCTL0_H = 0x00;
}
int main( void )
{
volatile unsigned int i;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
SetVCoreUp(1);
SetVCoreUp(2);
P1DIR |= BIT0; // P1.0 output
P8DIR |= 0x20; //P8.5 is pulse for solenoid.
P8DIR |= 0x40; //P8.6 is buzz
P2DIR |= 0x01; //output MClk for debug
P2SEL |= 0x01;
P11SEL |= BIT0; // P11.0 to output ACLK
P7SEL |= 0x03; // Select XT1
UCSCTL2 = FLLN0;
UCSCTL6 = XTS + XT2OFF +XT1DRIVE_2; // HF mode
UCSCTL6 &= ~(XT1OFF); // XT1 On
UCSCTL4 |= SELS_0 + SELM_0; // SMCLK=MCLK=XT1
__bis_SR_register(GIE);
// Loop until XT1 & DCO stabilize
do
{
UCSCTL7 &= ~(XT1HFOFFG +XT1LFOFFG + XT2OFFG + DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
for(i=0;i<0xFFFF;i++); // Delay for Osc to stabilize
}while (SFRIFG1&OFIFG); // Test oscillator fault flag
__no_operation();
while(1)
{
P8OUT ^= BIT6;
for(i=500;i>0;i–); // Delay (50000~= 37ms… 40Hz…
}
//return 0;
}