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.

MSP430F149: MSP430F149 UART communication problem

Part Number: MSP430F149

Hi, i need help, i have a project, its using MSP430F149 to deal with smart home security system. what i need to do now is connect my MSP to my laptop using RS232 to usb through UART and do some simple communication first. But what i face now is i cant really save those character sent from my laptop. My board receiver buffer can only receive one byte once time, so when i try to sent one sentence from my laptop terminal to my board and try to save it in another variable which i declared, the character it saved very messy and i have no idea whats wrong with it. For example, i sent my phone number which like 0124363516 , then i move the number byte by byte from receiver buffer to a variable and then transmit by transmitter buffer to my laptop terminal to show whats inside, its come out like ( 11,22,465) smthin like that. im using IAR embedded workbench IDE and realterm as my terminal. Below are my coding, can i have some help??thanks alot.

include "io430.h"
#include <in430.h> 
#include "nbc430.h"

#define uchar unsigned char
#define uint unsigned int

unsigned char s2;
unsigned char string2[] = { "Plesae Key In Your Message:\r\n" };
unsigned char s;
unsigned char string1[] = { "Please Key In Your Phone Number:\r\n" };

unsigned int i=0;

unsigned char buffer[];


void IO_init(void)
{
P3DIR4=1;P3DIR5=0; 

}
void delay(uint time)
{
uint i,j;
for(i = 0;i < time; i++)
{
for(j = 0;j < 30; j++);
}
}



void init_com( void )
{
P3SEL |= 0x30; 
ME1 |= UTXE0 + URXE0; 


UTCTL0 = SSEL0; 
UBR00 = 0x03; 
UBR10 = 0x00; 
UMCTL0 = 0x34; 

UCTL0 |= CHAR; 
UCTL0 &= ~SWRST; 
IE1 |= URXIE0+UTXIE0; 
IFG1&= ~UTXIFG0;
_EINT(); 
LPM3; 
}

#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx (void)
{

   while((IFG1&URXIFG0)==0);
   buffer[count]=RXBUF0;
  delay(1);
  TXBUF0 =buffer[count];
  count+=1;

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
IO_init(); ¯
init_com( ) ; 
while(1);

}

  • Hello Lay,
    have you referred the examples in slac015s.zip? You will get couple of examples for UART ECHO at different baud rate. You can just take reference of the same and modify your code.

    Regards,
    Vikas Chola
  • yea, i did refer the zip file, but those is just for echo, i need to store those character i receive from RX buffer, after i modify, the result i get kind of weird, can you help me to check out where's problem of my code up above the post?
  • Hello Lay,
    What is the Baud rate you are trying to achieve. In your code you haven't system clock. You should choose an example , change it Baud rate setting.. First make sure its working for UART ECHO and then just modify its UART ISR with your code:

    while((IFG1&URXIFG0)==0);
    buffer[count]=RXBUF0;
    delay(1);
    TXBUF0 =buffer[count];
    count++;


    It should work.

    Regards,
    Vikas Chola

  • the code i sent which is i take from the examples in slac015s.zip. it does work on the echo part, but for multiple character echo, the result come out very messy, for example like i trasnmitt "AA" , the first time and the second time it comes out is "A", then the third time only echo back "AA".
    i try alot of method to save the character receive from RXBUF0, but after i trasmit out back all those character it is in very messy form. its that the board problem or the timing problem or the delay problem?


    UTCTL0 = SSEL0; //choose ACLK as clock source.
    UBR00 = 0x03; // setting for baud rate.(9600)
    UBR10 = 0x00; // setting for baud rate.(9600)
    UMCTL0 = 0x34; // setting for baud rate.(9600)
  • Where is count defined? Is it volatile?

    Also, buffer needs to have a size defined.

  • yeah, i do defined in my coding, just do not attached here.
    int count=0;

    buffer size will affect the result come out become very messy? because i do not want to limit the number of character i sent, so i do not defined the size of buffer.
  • Again, it needs to be volatile.
    If you don't set the size of the buffer, C won't do it for you.

**Attention** This is a public forum