I'm having some problems using one of the built in timers on the MSP430F5438A. Let me first explain what I'm trying to do and how. Low power usage is the main concern here, I want to use a timer which fires an interrupt with periodicity T, an ISR sets a semaphore, if the semaphore is set, some code executes in the main work loop and an extremely simple message is sent. My code is based on the example code "AP_As_Data_Hub" which is distributed along with SimpliciTI 1.2. Below is an excerpt of the code, If required I can post the whole thing, but hopefully this is enough. I use the CC1120 as a radio.
void main (void)
{
/* some code */
/* part which seems to be incorrect */
UCSCTL4 |= SELA__VLOCLK; // set VLOCLK as source to ACLK
TA0CCTL0 |= CCIE; // turning on its CCIE bit makes it fire an interrupt when its counter value finally matches the value stored in TA0CCR0
TA0CCR0 = 37600; // ~ 4 sec (with VLOCLK as source, 6s is max)
TA0CTL |= TASSEL_1 + MC_1; // ACLK is source for timer, counts in upmode
uint8_t msg[1] = {1};
uint8_t *pMsg = &msg[0];
/* main work loop */
while(1)
{
/* Go to sleep while waiting for sAliveSem to be set by ISR */
__bis_SR_register(LPM3_bits+GIE); // LPM3 with interrupts enabled
/* the Alive semaphore has been set by an ISR and an "I'm alive" message is sent */
if(sAliveSem)
{
/* get radio ready...awakens in idle state */
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0);
/* Send message */
SMPL_Send(sLinkID1, pMsg, sizeof(msg));
/* radio off */
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0);
}
/* some code */
}
/* ISR */
#pragma vector = TIMER0_A1_VECTOR // timer0_A5
__interrupt void Timer_A (void)
{
sAliveSem = 1;
__bic_SR_register_on_exit(LPM3_bits); // exit LPM3
}