Part Number: MSP-EXP430FR4133
Hello, I am trying to leverage the Launchpad's OutofBox demo source to prove out some functionality and get some experience on the platform. I'm running into a problem where the TimerA0 ISR code doesn't seem to be executing and I am struggling to figure out why. Can someone please take a look and educate me? I feel like this is something very trivial that I just can't seem to spot.
One thing that is confusing me is that if I uncomment the printf() statements in the ISR, the code executes as expected. I am using the two LEDs in question here as a state-machine detection debug to find out if they are ever getting called. I am trying to post only the relevant code snippets, but can provide more if appropriate.
#pragma vector = TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR (void)
{
// Both button S1 & S2 held down
if (!(P1IN & BIT2) && !(P2IN & BIT6))
{
holdCount++;
isrcount++;
if (holdCount == 40)
{
// Stop Timer A0
Timer_A_stop(TIMER_A0_BASE);
// Change mode
// printf("Mode switch detected\n");
if (*mode == 0)
{
// this part works
// printf("Switching to ADCRAW mode\n");
(*mode) = ADCRAW_MODE;
P1OUT |= BIT0; // Turn LED1 On
P4OUT &= ~BIT0; // Turn LED2 Off
}
else if (*mode == ADCRAW_MODE)
{
// this part doesn't - this code only executes with the printf() statements uncommented, but then it functions normally
// printf("Switching to LINEARFLOW mode\n");
P1OUT &= ~BIT0; // Turn LED1 Off
P4OUT |= BIT0; // Turn LED2 On
(*mode) = LINEARFLOW_MODE;
}
else if (*mode == LINEARFLOW_MODE)
{
// printf("Switching to GPHFLOW mode\n");
P1OUT |= BIT0; // Turn LED1 On
P4OUT |= BIT0; // Turn LED2 On
(*mode) = GPHFLOW_MODE;
}
else if (*mode == GPHFLOW_MODE)
{
// printf("Switching to ADCRAW mode\n");
P1OUT |= BIT0; // Turn LED1 On
P4OUT &= ~BIT0; // Turn LED2 Off
(*mode) = ADCRAW_MODE;
}
__bic_SR_register_on_exit(LPM3_bits); // exit LPM3
}
}
// Button S1 released
if (P1IN & BIT2)
{
*S1buttonDebounce = 0; // Clear button debounce
P1OUT &= ~BIT0;
}
// Button S2 released
if (P2IN & BIT6)
{
*S2buttonDebounce = 0; // Clear button debounce
P4OUT &= ~BIT0;
}
// Both button S1 & S2 released
if ((P1IN & BIT2) && (P2IN & BIT6))
{
// Stop timer A0
Timer_A_stop(TIMER_A0_BASE);
__bic_SR_register_on_exit(LPM3_bits); // exit LPM3
}
}
int main(void)
{
//WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
WDT_A_hold(__MSP430_BASEADDRESS_WDT_A__); // Stop WDT
/*
* Launchpad Demo includes this code to wake up from low power mode
*/
// Check if a wakeup from LPMx.5
if (SYSRSTIV == SYSRSTIV_LPM5WU)
{
Init_GPIO();
__enable_interrupt();
switch(*mode)
{
case ADCRAW_MODE:
break;
case LINEARFLOW_MODE:
break;
case GPHFLOW_MODE:
break;
}
}
else // Else must be first time boot, run Inits
{
/*
* Init Routines before we do anything interesting
*/
Init_GPIO();
Init_Clock();
Init_RTC();
Init_LCD();
GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN2);
GPIO_clearInterrupt(GPIO_PORT_P2, GPIO_PIN6);
*S1buttonDebounce = *S2buttonDebounce = *mode = 0;
__enable_interrupt();
RTC_setModulo(RTC_BASE, 8191);
RTC_enableInterrupt(RTC_BASE, RTC_OVERFLOW_INTERRUPT);
RTC_start(RTC_BASE, RTC_CLOCKSOURCE_XT1CLK);
displayScrollText("FLOW DEMO"); // Boot message - Uppercase Chars Only
}
/*
* Main Loop
*/
while(1)
{
switch(*mode)
{
case ADCRAW_MODE:
displayScrollText("ADC RAW MODE SELECTED");
clearLCD();
// Call ADC Init & Start
break;
case LINEARFLOW_MODE:
displayScrollText("LINEAR FLOW MODE SELECTED");
clearLCD();
break;
case GPHFLOW_MODE:
displayScrollText("GPH NOT IMPLEMENTED");
clearLCD();
break;
default: // Must be first boot
displayScrollText("HOLD S1 AND S2 TO SWITCH MODES");
clearLCD();
break;
}
__bis_SR_register(LPM3_bits | GIE); // Enter LPM3
__no_operation();
}
}// End of main()