Question: MSP-EXP430FR6989 Using the Timer, Code bug or error somewhere. The main code is supposed to wait until the TAIFG flag is raised when the timer

MSP-EXP430FR6989 Using the Timer, Code bug or error somewhere.

The main code is supposed to wait until the TAIFG flag is raised when the timer resets to 0. Within the infinite for loop is a while loop that holds until the flag is raised. For some reason though no matter what I put into that while query, if its true the light stays on, if its false it never turns on. This leads me to believe that something about the timer isn't syntaxed or used correctly. Idk. Been working on this code for WAY longer than I'd like to admit.

I wrote the following code:

#include

#define redLED BIT0 // Red LED at P1.0

#define greenLED BIT7 // Green LED at P9.7

void config_ACLK_to_32KHz_crystal(void);

//****** Flashing the LED with Timer_A, continuous mode, via polling*********

void main(void) {

WDTCTL = WDTPW | WDTHOLD; // Stop the Watchdog timer

PM5CTL0 &= ~LOCKLPM5; // Enable the GPIO pins

P1DIR |= redLED; // Direct pin as output

P9DIR |= greenLED; // Direct pin as output

P1OUT &= ~redLED; // Turn LED Off

P9OUT &= ~greenLED; // Turn LED Off

config_ACLK_to_32KHz_crystal(); // Configure ACLK to the 32 KHz crystal (function call)

// Configure Timer_A

TA0CTL = TASSEL_1 | ID_0 | MC_2 | TACLR; // Use ACLK, divide by 1, continuous mode, clear TAR

TA0CTL &= ~TAIFG; // Ensure flag is cleared at the start

for(;;){ // Infinite loop

while(TA0CTL &= ~TAIFG){} // Empty while loop; waits here until TAIFG is raised

P1OUT ^= redLED; // Toggle the red LED

TA0CTL &= ~TAIFG; // Clear the flag

}

return;

}

//****** Configures ACLK to 32 KHz crystal*********

void config_ACLK_to_32KHz_crystal(){ // By default, ACLK runs on LFMODCLK at 5MHz/128 = 39 KHz

PJSEL1 &= ~BIT4; // Reroute pins to LFXIN/LFXOUT functionality

PJSEL0 |= BIT4; // Wait until the oscillator fault flags remain cleared

CSCTL0 = CSKEY; // Unlock CS registers

do {

CSCTL5 &= ~LFXTOFFG; // Local fault flag

SFRIFG1 &= ~OFIFG; // Global fault flag

}while((CSCTL5 & LFXTOFFG) != 0);

CSCTL0_H = 0; // Lock CS registers

return;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!