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 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 } } }
↧