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.

MSP430FR6989: MSP430FR6989

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

        }

  • Hi Sabin,

    I reviewed your code and it looks like you've setup your UART correctly. The only thing I see wrong is with the value you place in TA0CCR0.

    You set TA0CCR0 to 40000 and it's source clock is at ~9.4kHz. Doing the math 40000/9.3kHz = 4.3 sec which adds up with what you're seeing. Try placing a value of 10000 in TA0CCR0 and you should see an interval closer to 1 sec.

    Best regards,
    Caleb Overbay
  • Thank You for Your answer, I will do it

    BUT, It works fine (exactly 1 second) when I am using other program.. here is example of it where it works fine.
    I am so confused.



    #include <msp430.h>
    #define RED_LED 0x0001 // P1.0 is the red LED
    #define STOP_WATCHDOG 0x5A80 // Stop the watchdog timer
    #define ACLK 0x0100 // Timer_A ACLK source
    #define UP 0x0010 // Timer_A UP mode
    #define ENABLE_PINS 0xFFFE // Required to use inputs and outputs
    main()
    {
    WDTCTL = STOP_WATCHDOG; // Stop the watchdog timer
    PM5CTL0 = ENABLE_PINS; // Required to use inputs and outputs
    P1DIR = RED_LED; // Set Red LED as an output
    TA0CCR0 = 20000; // Sets value of Timer_0
    TA0CTL = ACLK + UP; // Set ACLK, UP MODE
    TA0CCTL0 = CCIE; // Enable interrupt for Timer_0
    _BIS_SR(GIE); // Activate interrupts previously enabled
    while(1); // Wait here for interrupt
    }

    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void Timer0_ISR (void)
    {
    static unsigned char x = 0; // Used to count number of elapses
    x = x+1; // Increment the elapse count
    if(x==15) // If count 15*20,000 = 300,000
    {
    P1OUT = P1OUT ^ RED_LED; // Toggle red LED
    x = 0; // Reset master count
    }
    }
  • Hi Sabin,

    This program is quite different from the one in your original post. You also need to remember the the VLO that is sourcing ACLK is not very accurate and can vary from 6kHz to 14kHz which could change the interval significantly.

    Best regards,
    Caleb Overbay
  • SO, Does the timer speed varies according to program ? is there any way to make timer faster?
    I calculated time by using (25micros * 40000 = 1sec). so using UART and Timer same time affects The timer? this showed a lot difference between two programs. ( it took 4sec (real time)to blink in original program but just 0.5sec(real time) to blink in second program. What might be the reason for such drastic change.
  • 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.

  • NOW I got what you were saying and I fixed it, Thank you.
    I have some confusion regarding "Baudrate" in the First program.

    Currently I have 9600 baudrate and I want to change it to 115200baud rate
    changing " UCA0BR0 = BR0_FOR_9600(0x34)" to " UCA0BR0 = (0x04)" changed my baudrate but messed up with my data
    Do I have to change any other things.


    "I calculated time by using (25micros * 40000 = 1sec)"
    I thought I was using LFMODCLK i.e. 5MHz/128 =25.6microsec.
  • 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

  • Hey, Caleb Thank you again. I solved that problem.

    Now I have problem in changing baudrate to 460800

    When I use 460800baudrate in "Low Frequency Baud-Rate Mode Setting",
    It works fine . I receive the real data I sent

    But when I use 460800baudrate in "Oversampling Baud-Rate Mode Setting ",
    I receive wrong data that I didn't even sent

    Here is my code for UART setting ,

    void select_clock_signals(void)
    {
    CSCTL0 = 0xA500; // "Password" to access clock calibration registers
    CSCTL1 = 0x0046; // Specifies frequency of main clock
    CSCTL2 = 0x0233; // 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; // 0000 1100

    }
    void use_9600_baud(void)
    {
    UCA0CTLW0 = UCSWRST; // Put UART into SoftWare ReSeT
    UCA0CTLW0 = UCA0CTLW0 | UART_CLK_SEL; // Specifies clock sourse for UART
    UCA0BR0 = 1; // Specifies bit rate (baud) of 9600
    UCA0BR1 = BR1_FOR_9600; //" BR1_FOR_9600" =0x00 Specifies bit rate (baud) of 9600
    UCA0MCTLW = (UCBRS0|UCBRS1|UCBRS2)+UCBRF_0+UCOS16;
    // UCA0MCTLW = CLK_MOD; // "Cleans" clock signal
    UCA0CTLW0 = UCA0CTLW0 & (~UCSWRST); // Takes UART out of SoftWare ReSeT
    }
  • Hey Caleb, I am looking for your help. I want to go to much higher baud rate as possible. What will be the highest baud rate and how can I get it? Looking solution for previous question too.
  • Hey Sabin,

    As you can see from Table 30-5 of the User's Guide, a baud rate of 460800 is not recommended for a BRCLK of 8 MHz in oversampling mode (UCOS16 set) due to the large amount of TX/RX error. I suggest that you increase BRCLK to 16 MHz if you would like to use a 460800 baud with oversampling. The maximum input clock frequency (16 MHz) and baud rate (4 Mbaud) is provided in Table 5-16 of the Datasheet. Operation with a baud of 921600 with minimal error should be achievable while not oversampling.

    Regards,
    Ryan
  • Thank you for helping out
    I tried what you said but whenever I change my Clock to 16MHz, the UART transmission stops working and even the LED doesnt blink here is my code.

    #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 STOP_WATCHDOG 0x5A80 // Stop the watchdog timer
    #define ACLK 0x0100 // Timer_A ACLK source
    #define UP 0x0010 // Timer_A Up mode
    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; // 40000 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(GIE); // Activate enable interrupt
    while(1);
    }

    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void Timer0_ISR (void)
    {
    P1OUT = P1OUT ^ RED_LED;
    UCA0TXBUF =0x55;
    }

    void select_clock_signals(void)
    {
    CSCTL0 = 0xA500; // "Password" to access clock calibration registers
    CSCTL1 = 0x0048; // Specifies frequency of main clock to 16 MHZ
    CSCTL2 = 0x0233; // Assigns additional clock signals
    CSCTL3 = 0x0000; // Use clocks at intended frequency, do not slow them down
    }

    //*********************************************************************************
    //* Used to Give UART Control of Appropriate Pins *
    //*********************************************************************************
    void assign_pins_to_uart(void)
    {
    P4SEL1 = 0x00; // 0000 0000
    P4SEL0 = BIT2;
    }
    //*********************************************************************************
    //* Specify UART Baud Rate *
    //*********************************************************************************
    void use_9600_baud(void)
    {
    UCA0CTLW0 = UCSWRST; // Put UART into SoftWare ReSeT
    UCA0CTLW0 = UCA0CTLW0 | UART_CLK_SEL; // Specifies clock sourse for UART
    UCA0BR0 = 17; // Specifies bit rate (baud) of 9600
    UCA0BR1 = 0; // Specifies bit rate (baud) of 9600
    //UCA0MCTLW = CLK_MOD; // "Cleans" clock signal
    UCA0MCTLW = (UCBRS0 | UCBRS1 ) + UCBRF_0 ;
    UCA0CTLW0 = UCA0CTLW0 & (~UCSWRST); // Takes UART out of SoftWare ReSeT


    }
  • One FRAM waitstate (RFCTL0 = FRCTLPW | NWAITS1;) is required by the device datasheet for MCLK operation beyond 8MHz before configuring the clock system.

    Regards,
    Ryan
  • Hi Sabin,

    Do you still need help with this issue?

    Best regards,
    Caleb Overbay
  • Thanks, My problem has been solved

**Attention** This is a public forum