Hello,
I'm working on a project with an MSP430g2955. I have a 32.768 KHz crystal with 12pF capacitors.
I need to generate a 1sec timer and I've chose to use the Timer B.
The problem is that with the timer B enabled, the sistem restart after 1-2 minutes. The hardware reset on the pin 7 is always up, so I don't think that this is the problem.
This is my code for the clock:
void clock_init()
{
// P2SEL|=(0x40+0x80);
if (CALBC1_1MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;
do {
IFG1 &= ~OFIFG; // Clear OSC Fault flag
__delay_cycles(50000); // Time for flag to set again
} while (IFG1 & OFIFG); // Loop while OSC Fault flag is set
IE1 |= OFIE; // re-enable osc fault interrupt
}
The code for the Timer B is very simple:
void timerb_init()
{
//TBCCTL0 = CCIE; // TBCCR0 interrupt enabled
TBCCR0 = 32768;
TBCTL = TBSSEL_1 | MC_1; // ACLK, contmode
}
#pragma vector=TIMERB0_VECTOR
__interrupt void Timer_B (void)
{
if(timerset.sec>0)
timerset.sec--;
else
{
if(timerset.min>0)
timerset.min--;
else
{
if(timerset.hour>0)
{
timerset.hour--;
//time_sec=update_time(0x03);
//time_min=update_time(0x04);
//time_h=update_time(0x05);
//time_d=update_time(0x06);
}
else
{
timerset.day--;
timerset.hour=23;
}
timerset.min=59;
}
timerset.sec=59;
}
}
The timer B is enabled in the main:
case 13: TBCCTL0 |= CCIE; lcd_command(0x30); P1OUT|=LEDRED; sprintf(str,"%d:%d:%d ",timerset.hour,timerset.min,timerset.sec); lcd_str_send(str,1); break;
Do you see any problem in everything I posted?
Thank you for helping me out.
Best regards
Nicola