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.

msp430f5438a timer interupt and UART

Other Parts Discussed in Thread: MSP430WARE

I've tried to create a RTC of 1ms, I set up a timer into at 1Mhz to count up 1000, this should have resulted in an interupt  every 1ms. However I get something around 0.6ms.

Next, I'm using SPI (UCB0) and UART (A1) and when ever I try to run a code with SPI, UART and the RTC. Everything breaks up. note that I've also tried using the B time, but I was unable to being interupted by the timer (I could really apprititate if someone could drop a small example of the usage of the second time in the UPTO mode, there are abosololy nothing online but the user guide, which is not that friendly)

P.S I'm using the TrxEB board

void main(){
   WDTCTL = WDTPW + WDTHOLD;
   //(this had no affect on the frequency of calling)
   TA0CCR0 = 1000;
   // using MCSLK 1MHZ, UP TO CCR0, CLEAR, Enable interupt
   TA0CTL = TASSEL_2 + MC_1 + TACLR + TAIE; 
   __enable_interupt();
   while(1);
}

// should be called when reaching CCR0
#pragma vector=TIMER0_A0_VECTOR
__interupt void TIMER0_A0_ISR(void){
   // this was called at around 16khz
} 

  • If you want CCR0 to cause an interrupt on reaching it's value you have to enable CCIE interrupt in TA0CCTL0. If you enable TAIE then you enable the overflow-interrupt of the timer (reaching 65535) and you do not have an ISR for that because it is in TIMER0_A1_VECTOR.

    Maybe it seems that your ISR is called at 16kHz, but your MCU is restarting continously because the interrupt is pointing to nowhere. Just a guess.


    Have a look at the MCUs header file - there you can see the makros for the different interrupt sources. And have a look at the user's guide to see the different registers of the timer.

  • Try:

    void main( void )
    {
      WDTCTL   = WDTPW + WDTHOLD;
      TA0CCR0  = 1000;
      TA0CCTL0 = CCIE;
      TA0CTL   = TASSEL_2 + MC_1;
       
      __enable_interupt();
       
      while(1);
    }
    // should be called when reaching CCR0
    #pragma vector=TIMER0_A0_VECTOR
    __interupt void TIMER0_A0_ISR( void )
    {
    // Do something }

    Not tested it...

    By the way - where do you set your frequency to 1MHz?

  • Hi,

    TI provide a number of code examples in the MSP430Ware package that cover this sort of application.

    The following is from one of their examples:

    #include <msp430.h>
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      P1DIR |= 0x01;                            // P1.0 output
      TA1CCTL0 = CCIE;                          // CCR0 interrupt enabled
      TA1CCR0 = 50000;
      TA1CTL = TASSEL_2 + MC_1 + TACLR;         // SMCLK, upmode, clear TAR
    
      __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, enable interrupts
      __no_operation();                         // For debugger
    }
    
    // Timer A0 interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=TIMER1_A0_VECTOR
    __interrupt void TIMER1_A0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(TIMER1_A0_VECTOR))) TIMER1_A0_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      P1OUT ^= 0x01;                            // Toggle P1.0
    }
    

    This uses timer A1 rather than A0 but provides the basics. There are other examples for SPI and UART in the package.

    The code that you have posted seems to be working but is not giving you an accurate time base as you arte using the DCO to provide the clock. If you check the datasheet for this device you will find that the DCO has a very wide tolerance on its frequency. You need to look at using an external crystal to improve your accuracy. Some MSP430 devices have a REFO oscillator which you may be able to use. Not sure if this is in the processor that you have, but if it is should be more accurate than the DCO

    Regards

       Roy

  • I guess that would be really useful if those examples were available somewhere online (github?), and not in some zip/exe file that cannot be index by search engines.

    Thanks, it solved my problem

**Attention** This is a public forum