This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
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
}
Hi Sabin,
The timer speed is dependent on the clock you provide it. In this case you're sourcing it from the VLO which is a slower and less accurate source. If you want to increase the speed of the timer, you should provide it a different source.
Sabin Timsina said:I calculated time by using (25micros * 40000 = 1sec)
Where do you get 25us from? The VLO oscillated at ~9.4kHz which is a ~106us period.
Sabin Timsina said:so using UART and Timer same time affects The timer?
I'm not sure I understand this question. You've setup your timer differently in each program you showed me. In the first you set TA0CCR0 to 40000 and the second you set TA0CCR0 to 20000. Then the logic within your ISR is much different as well. All of this doesn't account for the natural variation of the VLO as well. Regardless, I wouldn't expect the LED to blink in 0.5sec interval for the second program.
How did changing the TA0CCR0 register in the first program affect your interval?
Best regards,
Caleb Overbay
Thank you so much.
Yeah changing TA0CCR0 register in first program worked for me.
I am sorry about second question. I mean each 20000 count is equal to 0.5 sec in second program. So due to this. The LED toggles after every 7.5 sec
I am sorry, I am confused. I think I have used same codes for timing in both program but I might be wrong as I don't know much about it in detail.
Which lines of codes changes clock source? I want to increase my clock speed, How can I change it.
Regarding 25miccosec, I have read it in a book and it says it takes 25microsec to count from 0 to 1. I am not sure about the clock source it uses.
Hoping help from you so that I can clear my confusion.
Hi Sabin,
I recommend using the MSP430 Baud Rate Calculator to determine the appropriate register settings for 115200 baud. Try it out and let me know how it works.
Best regards,
Caleb Overbay
**Attention** This is a public forum