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.

MSP430F2418: Multiple data transmission through UART

Part Number: MSP430F2418

Hi,

I am trying to send multiple sensor data (assume integer value)   from MSP430 through UART interface. I am using 'Tera Term' to view data. 

While sending one senor data repeatedly (at a particular interval, using timer interrupt) through UART, there is no problem. But while sending multiple senor data one after another, it is not sending properly.

 

The important part is TIMER ISR and UART ISR. As you can see, every ~0.5 sec Timer ISR will be called and every 5 sec (0.5 x 10) the "if" statement will be executed.

My observations on UART terminal:  Instead of getting            60003000 //-------5sec gap ---------//  60003000 //-----------5sec gap------------// 60003000 ----

                                                    I am getting                    63000     // -------5sec gap ---------//  63000        //-------5sec gap --------- -----// 6300-------    

                                                   So, only the 1st character of num1 is sent and then whole num2, and this steps repeats.

 

So, can anybody please tell me, what the things need to be modified in Timer ISR and Uart ISR to get 60003000. Thanks in advance and Happy New Year.

//*************************My Code***********************************//


#include <msp430.h> char string[16]; unsigned int j; //Counter // for simplicity, assume num1 and num2 as two senor value
unsigned int num1 = 6000; unsigned int num2 = 3000; unsigned int timerIsrCount = 0; /* * Function to convert integer to a string format, so that, it can be transferred through UART */ void tostring(char string[], int num) { ----------------------------// for simplicity I removed this } int main() { WDTCTL = WDTPW + WDTHOLD; // Stop WDT /* * initialization of crystal and frequency */ -----------------------// for simplicity I removed this /* * initialization of TIMERA0 */ ---------------------------// for simplicity I removed this /* * initialization of UART0 communication */ P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 = 8; // 1MHz 115200 UCA0BR1 = 0; // 1MHz 115200 UCA0MCTL = UCBRS2 + UCBRS0; // Modulation UCBRSx = 5 UCA0CTL1 &= ~UCSWRST; // Initialize USCI state machine while (1) { __bis_SR_register(LPM0_bits + GIE); // LPM0 } } /* * TIMERA0 ISR // every ~0.5 sec this ISR will be executed */ #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) { timerIsrCount += 1; if( timerIsrCount == 10) // Action every 0.5x10 = 5 Sec. {
// Converting and sending num1

tostring(string, num1); // This function returns value, after int to string conversion.
// The converted data is stored in char array named "string" j = 0; UC0IE |= UCA0TXIE; // Enable USCI_A0 TX interrupt UCA0TXBUF = string[j++]; // send 1st character // Converting and sending num2
tostring(string, num2); j = 0; UC0IE |= UCA0TXIE; // Enable USCI_A0 TX interrupt UCA0TXBUF = string[j++]; // send 1st character timerIsrCount = 0; // making ready for next execution }
else // else do nothing
{
}
}
/* * UART ISR */ #pragma vector=USCIAB0TX_VECTOR __interrupt void USCI0TX_ISR(void)
{ while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready? { UCA0TXBUF = string[j++]; // TX next character if (j == sizeof string - 1) // TX over? { UC0IE &= ~UCA0TXIE; // Disable USCI_A0 TX interrupt } } }

 

  • hello dinkar,
    first of all if you just want to send two integers at every 5 sec why are you using uart transmit interrupt ISR. i don't think you need that you can easily send without using that.

    Second thing if you want to check what is exactly happening in your current program
    do following take an oscilloscope
    1) make a gpio high(1) at line 72 then again pull down(0) it at line 84
    2) make another gpio high(1) at line 97 and again pull down(0) it at line 104.

    3) watch both pins on oscilloscope on different channels .
    4) now watch your tx pin with respect to both pulse one by one.

    try to make some conclusion you will get your answer.
  • Hello Sasuke

    1st of all thanks for the reply.
    Actually my goal is not only to send data through UART every 5 sec. It is a small portion of a project. Where manipulated data will be sent at a particular time via UART.

    So, I need to use Timer interrupt or RTC. Here for simplicity I have used timer interrupt and sent data every 5 sec.

    So here whats actually happening is, from the Timer interrupt ISR, I am calling UART ISR twice. But it is only executing Once. That's why after the 1st character of num1 (sending 1st character of num1, is not a part of ISR (line 75)) got sent, it is not going to ISR. But the second integer num2 is executing properly.

    So, is there anything like: from one ISR (take example Timer ISR) we can call another particular ISR (take example UART ISR) only Once during one time execution?? Coz I an trying to call UART ISR twice, but it is only executing once.
  • hello dipankar,

                                     happy new year :)    ,  clear me on one thing do you have your data(of both sensors)? which you want to send before entering in the if loop timer ISR (you mentioned in your code)  which represent your 5 sec.   In your case what you says  as integer 6000 & 3000.

    what i am saying if i am correct then you have

                                                                            sensor 1=     integer 6000  ( 0x1770 hex)

                                                                            sensor 2=     integer 3000  ( 0x0BB8 hex) before entering to 5 sec loop in timer ISR

    and as 5 second time passes you want to send it through UART. (and of-course this is not the whole application a part of it).

    what i am suggesting is why you are calling uart ISR from timer ISR twice? or even why you are calling UART ISR.

    instead of that

    you can make an array say             transmit_buffer[4]={0x17,0x70,0x0B,0xB8} // data you want to send

    and in your 5 second if loop           make a flag high say send_flag=1;

    in your        

                     main ()

                   {       

                      //     your application code

                       if (send_flag)

                             {

                                   // send your complete array transmit_buffer   {without calling any UART ISR }

                                   //make send_flag=0;

                              }

                    }

    correct me if i am wrong.

    thanks

  • Hello sasuke,

    Yea you are right. Two senor data are num1 and num2. In actual application this value will be varied with respect to time, but here I made two constant values for simplicity.

    Also, the process you said is working. Instead of UART ISR, I am directly placing the values in TX buffer in Timer interrupt only and uploading the string data into TXBUF until the string ends. After sending the num1 data I am repeating the same for num2 and it is working very WELL...

    Thanks man for replies....

**Attention** This is a public forum