Part Number: MSP430FR6989
Hello, I am trying to send data in every interval of 1 second and blink led same time. But I don't know why the time is delayed. It takes much more than 1 sec time to blink led. And I receive 1 character "V" (0x56) at every interval of 4 sec. Any help will be appreciated. If there in any thing wrong with Interrupt or transmission code then do notify me through comment.
UART (select_clock_signal) might have caused this as when I remove these functions. It starts to run on required speed but goes wild and doesn't receive data that I needed
#include <msp430.h>
#define RED_LED 0x0001
#define ENABLE_PINS 0xFFFE // Required to use inputs and outputs
#define UART_CLK_SEL 0x0080 // Specifies accurate clock for UART peripheral
#define BR0_FOR_9600 0x34 // Value required to use 9600 baud
#define BR1_FOR_9600 0x00 // Value required to use 9600 baud
#define CLK_MOD 0x4911 // Microcontroller will "clean-up" clock signal
#define STOP_WATCHDOG 0x5A80 // Stop the watchdog timer
#define ACLK 0x0100 // Timer_A ACLK source
#define UP 0x0010 // Timer_A Up mode
#define ADC12_P84 0x0007 // Use input P8.4 for analog input
void select_clock_signals(void); // Assigns microcontroller clock signals
void assign_pins_to_uart(void); // P4.2 is for TXD, P4.3 is for RXD
void use_9600_baud(void); // UART operates at 9600 bits/second
main(void)
{
WDTCTL = STOP_WATCHDOG; // Stop WDT
PM5CTL0 = ENABLE_PINS; // Enable pins
P1DIR = RED_LED;
TA0CCR0 = 40000; // 400 count is 1s
TA0CTL = ACLK + UP; // Set ACLK, UP MODE for Timer_0
TA0CCTL0 = CCIE; // Enable interrupt for Timer_
select_clock_signals(); // Assigns microcontroller clock signals
assign_pins_to_uart(); // P4.2 is for TXD
use_9600_baud(); // UART operates at 9600 bits/second
_BIS_SR(LPM0_bits | GIE); // Activate enable interrupt
while(1);
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer0_ISR (void)
{
P1OUT = P1OUT ^ RED_LED;
UCA0TXBUF = 0x56;
}
void select_clock_signals(void)
{
CSCTL0 = 0xA500; // "Password" to access clock calibration registers
CSCTL1 = 0x0046; // Specifies frequency of main clock
CSCTL2 = 0x0133; // Assigns additional clock signals
CSCTL3 = 0x0000; // Use clocks at intended frequency, do not slow them down
}
void assign_pins_to_uart(void)
{
P4SEL1 = 0x00; // 0000 0000
P4SEL0 = BIT2;
}
void use_9600_baud(void)
{
UCA0CTLW0 = UCSWRST; // Put UART into SoftWare ReSeT
UCA0CTLW0 = UCA0CTLW0 | UART_CLK_SEL; // Specifies clock sourse for UART
UCA0BR0 = BR0_FOR_9600; // Specifies bit rate (baud) of 9600
UCA0BR1 = BR1_FOR_9600; // Specifies bit rate (baud) of 9600
UCA0MCTLW = CLK_MOD; // "Cleans" clock signal
UCA0CTLW0 = UCA0CTLW0 & (~UCSWRST); // Takes UART out of SoftWare ReSeT
}