Hi,
when compiling this program (for testing the timer A0 on cc430f6137) with msp430-gcc 4.4.5 there is a problem. It seems as if the controller hangs up. According to the debugger (mspdebug, also used for flashing the controller) the Timer0_Start doesn't jump back to main(). I tried some combinations and it looks like the instruction/ function call before the infinite-loop isn't executed correctly. When adding code into the loop the controller hangs there, so the loop i executed only once. I compiled with -O0, so I don't think the compiler is optimizing someting imporant away. Do you see any problems?
#include <cc430x613x.h>
#include <signal.h>
int Timer0_Start(uint16_t ticks)
{
// Clear and start timer now
// Continuous mode: Count to 0xFFFF and restart from 0 again - 1sec timing will be generated by ISR
TA0CTL |= TASSEL0 + MC1 + TACLR;
TA0CTL |= MC_2;
// Delay based on current counter value
TA0CCR0 = TA0R + ticks;
// Reset IRQ flag
TA0CCTL0 &= ~CCIFG;
// Enable timer interrupt
TA0CCTL0 |= CCIE;
return 0;
}
//prints 'h' on the display
void print()
{
unsigned char * lcdmem;
// Clear entire display memory
LCDBMEMCTL |= LCDCLRBM + LCDCLRM;
// LCD_FREQ = ACLK/16/8 = 256Hz
// Frame frequency = 256Hz/4 = 64Hz, LCD mux 4, LCD on
LCDBCTL0 = (LCDDIV0 + LCDDIV1 + LCDDIV2 + LCDDIV3) | (LCDPRE0 + LCDPRE1) | LCD4MUX | LCDON;
// LCB_BLK_FREQ = ACLK/8/4096 = 1Hz
LCDBBLKCTL = LCDBLKPRE0 | LCDBLKPRE1 | LCDBLKDIV0 | LCDBLKDIV1 | LCDBLKDIV2 | LCDBLKMOD0;
// I/O to COM outputs
P5SEL |= (BIT5 | BIT6 | BIT7);
P5DIR |= (BIT5 | BIT6 | BIT7);
// Activate LCD output
LCDBPCTL0 = 0xFFFF; // Select LCD segments S0-S15
LCDBPCTL1 = 0x00FF; // Select LCD segments S16-S22
// LCD_B Base Address is 0A00H page 30 y in SALS554 document
// show 'h'
lcdmem = (unsigned char *)0x0A21;
*lcdmem = (unsigned char)(*lcdmem | (BIT2+BIT1+BIT6+BIT0));
}
interrupt (TIMER0_A0_VECTOR) foo(void)
{
print();
}
interrupt (TIMER0_A1_VECTOR) bar(void)
{
print();
}
int main()
{
Timer0_Start(5);
//wait for interrupts
while(1)
{
}
return 0;
}