Hello;
My software frezes after some time at 8Mhz and not working at 16mhz. I am suspect about timer module, uart configration and main clock configration;
Can you please check and comment if i made any mistake in library.
clock configration
void initClockTo8MHz()
{
__bis_SR_register(SCG0); // disable FLL
// CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source
CSCTL0 = 0; // clear DCO and MOD registers
CSCTL1 &= ~(DCORSEL_7); // Clear DCO frequency select bits first
CSCTL1 |= DCORSEL_3; // Set DCO = 8MHz
CSCTL2 = FLLD_0 + 243;
__delay_cycles(3);
__bic_SR_register(SCG0); // enable FLL
while (CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1))
; // FLL Lock
}
void initClockTo16MHz()
{
// Configure one FRAM waitstate as required by the device datasheet for MCLK
// operation beyond 8MHz _before_ configuring the clock system.
FRCTL0 = FRCTLPW | NWAITS_1;
// Clock System Setup
__bis_SR_register(SCG0); // disable FLL
CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source
CSCTL0 = 0; // clear DCO and MOD registers
CSCTL1 &= ~(DCORSEL_7); // Clear DCO frequency select bits first
CSCTL1 |= DCORSEL_5; // Set DCO = 16MHz
CSCTL2 = FLLD_0 + 487; // DCOCLKDIV = 16MHz
__delay_cycles(3);
__bic_SR_register(SCG0); // enable FLL
while (CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1))
; // FLL locked
}
uart configration
* This is for 115200 Baud rate (8Mhz)
*/
UCA1BRW = 4;
UCA1MCTLW |= 0x0500;
UCA1MCTLW |= UCBRF_3;
UCA1MCTLW |= UCOS16_1;
UCA1CTLW0 &= ~UCSWRST;
UCA1CTLW1 = 0;
UCA1IE |= UCRXIE;
/*
* This is for 115200 Baud rate (16Mhz)
*/
/*
UCA1BRW = 8;
UCA1MCTLW |= 0x0000;
UCA1MCTLW |= UCBRF_11;
UCA1MCTLW |= UCOS16_1;
UCA1CTLW0 &= ~UCSWRST;
UCA1CTLW1 = 0;
UCA1IE |= UCRXIE;
*/
timer library
#include <msp430.h>
#include <stdint.h>
#include "TIMER_MODULE.h"
/*
* This function will initialize the Timer module
*/
void timerInit(void)
{
TA1CCTL0 |= CCIE; // TACCR0 interrupt enabled
TA1CCR0 = 1000 - 1; // timer will roll over every 1000 clock cycle / pwm period
TA1CTL |= TASSEL_2 + ID_3 + MC_1 + TACLR; // TimerA1 SMLCK(TASSEL_2), CLOCK divide by 8(ID_3) pwm start(MC_1), Reset the timer clear TAR (TACLR)
}
/*
* This function will return the current time with resolution
* of 10 microsecond in each ticking
*/
uint32_t timerMicros(void)
{
return micros + TA1R;
}
/*
* This function will return the current time with resolution
* of 1 millisecond in each ticking
*/
uint32_t timerMillis(void)
{
return millis;
}
/*
* This function will return the current time with resolution
* of 1 second in each ticking
*/
uint32_t timerSecond(void)
{
return (millis / 1000);
}
/*
* This function will reset all timers
*/
void timerReset(void)
{
millis = 0;
}
/*
* This function will reset millis
*/
void timerResetMillis(void)
{
millis = 0;
}
/*
* This function will reset seconds
*/
void timerResetSecond(void)
{
second = 0;
}
/*
* This is an ISR to handle the timer
*/
#pragma vector = TIMER1_A0_VECTOR
__interrupt void Timer_A_CCR0_ISR(void)
{
millis++;
micros += 1000;
}