Part Number: MSP-EXP430FR2433
Other Parts Discussed in Thread: MSP430FR2633
Tool/software: Code Composer Studio
Hi,
I'm using MSP-EXP430FR2433. On my launchboard I got 2 LEDs (P1.0/RED and P1.1/Green) and two Switches (P2.3 and P2.7). My project is to change the red LED's blinking speed. If I press the P2.3 switch it reduces the speed and if I press the P2.7 switch it raises the speed of the blinking. I know this part. But I don't know how to get the Timer's value with UART, so I can see it on my PC. Can somebody help me, please?
Thanks
Here is my code:
#include <msp430.h>
unsigned int aku1 = 0; // counter1
unsigned int aku2= 0; // counter2
int counter = 0x1111;
#define SMCLK_115200 0
#define SMCLK_9600 1
#define UART_MODE SMCLK_115200//SMCLK_9600//
void initUART()
{
// Configure USCI_A0 for UART mode
UCA0CTLW0 |= UCSWRST; // Put eUSCI in reset
#if UART_MODE == SMCLK_115200
UCA0CTLW0 |= UCSSEL__SMCLK; // CLK = SMCLK
// Baud Rate Setting
// Use Table 21-5
UCA0BRW = 8;
UCA0MCTLW |= UCOS16 | UCBRF_10 | 0xF700; //0xF700 is UCBRSx = 0xF7
#elif UART_MODE == SMCLK_9600
UCA0CTLW0 |= UCSSEL__SMCLK; // CLK = SMCLK
// Baud Rate Setting
// Use Table 21-5
UCA0BRW = 104;
UCA0MCTLW |= UCOS16 | UCBRF_2 | 0xD600; //0xD600 is UCBRSx = 0xD6
#else
# error "Please specify baud rate to 115200 or 9600"
#endif
UCA0CTLW0 &= ~UCSWRST; // Initialize eUSCI
UCA0IE |= UCTXIE + UCRXIE; // Enable USCI_A0 RX interrupt
}
void initClockTo16MHz()
{
// Configure one FRAM waitstate as required by the device datasheet for MCLK
// operation beyond 8MHz _before_ configuring the clock system.
FRCTL0 = FRCTLPW | NWAITS_1;
__bis_SR_register(SCG0); // disable FLL
CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source
CSCTL0 = 0; // clear DCO and MOD registers
CSCTL1 &= ~(DCORSEL_7); // Clear DCO frequency select bits first
CSCTL1 |= DCORSEL_5; // Set DCO = 16MHz
CSCTL2 = FLLD_0 + 487; // set to fDCOCLKDIV = (FLLN + 1)*(fFLLREFCLK/n)
// = (487 + 1)*(32.768 kHz/1)
// = 16 MHz
__delay_cycles(3);
__bic_SR_register(SCG0); // enable FLL
while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // FLL locked
CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK;
}
void initGPIO()
{
// Configure GPIO
P1DIR |= BIT0; // P1.0 output
P1OUT &= ~BIT0; // P1.0 törlés
P1DIR |= BIT1; // P1.1 output
P1OUT &= ~BIT1; // P1.1 törlés
P2REN |= BIT3; // felhúzóellenállás engedélyezése
P2OUT |= BIT3; // Select pull-up mode for P2.3
P2IE |= BIT3; // P2.3 interrupt engedélyezés
P2IES |= BIT3; // P2.3 Hi/lo edge
P2IFG &= ~BIT3; // P2.7 IFG törlése
P2REN |= BIT7; // Enable internal pull-up/down resistors
P2OUT |= BIT7; // Select pull-up mode for P2.7
P2IE |= BIT7; // P2.7 interrupt enabled
P2IES |= BIT7; // P2.7 Hi/lo edge
P2IFG &= ~BIT7; // P2.7 IFG törlése
}
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
initGPIO();
initClockTo16MHz();
initUART();
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
//TimerA0 konfig
TA0CCTL0 |= CCIE; // TACCR0 interrupt enabled
TA0CCR0 = 0x1111;
TA0CTL |= TASSEL__SMCLK | MC_1 | ID__8; // SMCLK, up to equal mode
//TimerA1 konfig
TA1CCR0 = 0x5fff;
TA1CTL |= TASSEL__SMCLK | MC_1 | ID__8; // SMCLK, up to equal mode
__bis_SR_register(LPM0_bits | GIE); // LPM3(low power mode) és interruptok engedélyezése
__no_operation(); // végtelen ciklus
}
// Timer A0 interrupt service routine
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
P1OUT ^= BIT0; // P1.0 LED villogtatása
}
// Timer A1 interrupt service routine
#pragma vector = TIMER1_A0_VECTOR //P1.1 LED visszajelző beállítása
__interrupt void Timer_B (void)
{
if(aku1 == aku2)
{
TA1CCTL0 &= ~CCIE;
aku1=0;
}
else
{
P1OUT ^= BIT1;
aku1++;
}
}
// Port 2 interrupt service routine
#pragma vector=PORT2_VECTOR
__interrupt void Port_2_7(void)
{
if(P2IFG & BIT3) //ha a P2.3-as gomb interrupt flagje aktív
{
if(TA0CCR0 == 0x0000) // ha a TimerA0 elérte a minimumot
{
P2IFG &= ~BIT3; // P2.3 IFG torles
TA1CCTL0 |= CCIE; // TA1CCR0 interrupt engedelyezes
TA1CCR0 = 0x8fff; // TimerA1 sebességének megadása
TA0R = 0; // TimerA0 counter nullázása
UCA0RXBUF=TA0CCR0;
aku2 = 4; // 2-t villan a visszajelző LED (P1.1)
}
else
{
P2IFG &= ~BIT3; // P2.3 IFG törlés
TA0CCR0 = TA0CCR0 - 0x1111; // TimerA0 értékének csökkentese
counter = counter - 0x1111;
TA0R = 0; // TimerA0 counter nullázása
TA1CCTL0 |= CCIE; // TimerA1 interrupt engedélyezés
TA1CCR0 = 0x5fff; // TimerA1 sebességének megadása
UCA0RXBUF = TA0CCR0;
aku2 = 4; // 2-t villan a visszajelző LED (P1.1)
}
}
if(P2IFG & BIT7) // ha a P2.7-as gomb interrupt flagje aktív
{
if(TA0CCR0 == 0xFFFF) // ha a TimerA0 elérte a maximumot
{
P2IFG &= ~BIT7; // P2.7 IFG cleared
TA1CCTL0 |= CCIE; // TimerA1 interrupt engedelyezes
TA1CCR0 = 0x8fff; // TimerA1 sebességének megadása
TA0R = 0; // TimerA0 counter nullázása
UCA0RXBUF=TA0CCR0;
aku2 = 6; // 3-t villan a visszajelző LED (P1.1)
}
else
{
P2IFG &= ~BIT7; // P2.7 IFG cleared
TA0CCR0 = TA0CCR0 + 0x1111; // TimerA0 értékének növelése
counter = counter + 0x1111;
TA0R = 0; // TimerA0 counter nullázása
TA1CCTL0 |= CCIE; // TimerA1 interrupt engedelyezes
TA1CCR0 = 0x5fff; // TimerA1 sebességének megadása
UCA0RXBUF = TA0CCR0;
aku2 = 6; // 3-t villan a visszajelző LED (P1.1)
}
}
}
//******************************************************************************
// UART Interrupt ***********************************************************
//******************************************************************************
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG))
{
case USCI_NONE: break;
case USCI_UART_UCRXIFG:
/* while(!(UCA0IFG&UCTXIFG));
UCA0TXBUF = UCA0RXBUF;
__no_operation();*/
break;
case USCI_UART_UCTXIFG:
while(!(UCA0IFG&UCRXIFG));
UCA0RXBUF = UCA0TXBUF;
__no_operation();
break;
case USCI_UART_UCSTTIFG: break;
case USCI_UART_UCTXCPTIFG: break;
}
}