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.

MSP430 UART mode--Interrupt

Other Parts Discussed in Thread: MSP430FG4619, ENERGIA

hello professors,

I'm new to the msp430FG4619 chip, and now I am doing the project which needs to use uart mode to get the data from the radar and send it to the sd card, but at the same time the collected time should be accurate to the millisecond.

However, the fg4619 chip doesnt have the millisecond part, so I need to use timer module to synchronize with the RTC second part. But after I am facing with more complicated problem, I need to do accurate as much as I can among the uart mode, timer module and SD writing...It means they should be synchronized..I think it is hard to achieve, cause I need to manage the whole structure of the code, but  I am a freshman in this area...

After I built the connection, the chip began to receive the data, but there is big gap time between rtc part and millisecond part.  Could you help me to give some suggestions to my code in uart mode? because I think the code I wrote in the uart interrupt may not be appropriate, really grateful for your time.

Here is my code in the interrupt:

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
 
  if(UCA0RXBUF==0x52)  //--R(1), 0101 0010 0x52   
    receive_r1[0] = UCA0RXBUF;
  if(UCA0RXBUF == 0xB1)  //--------R(1) --> set 10: --> for the R1 1011 0001, orignally it is 0x31--0011 0010
    cnt_r1 |= 1;  //this should be deleted
  if(cnt_r1)
    {
      if(k1==1)
        {
          receive_r1[1] = UCA0RXBUF & 0x3F;  //--for the T1 1011 0001 -- 0xB1
          k1++;
        }
          t1++;  //jump out for this turn, when t2=3, the value of the BUF will again to send its value
      if(t1>=3)
        receive_r1[k1++] = UCA0RXBUF;
      if(k1 == sizeof (receive_r1) -1)
        {
          P1OUT = P1OUT^BIT0;
          k1=1;
          t1=1;
          cnt_r1 &= ~1;
          count_r1|=1;
        }     
    }
 
  if(UCA0RXBUF==0xD2)  //--R(2), 0101 0010 0x52 --> 1101 0010 0xD2
    receive_r2[0] = UCA0RXBUF & 0x7F;
  if(UCA0RXBUF == 0xB2)  //--------R(2) --> set 10: --> for the R1 1011 0010, orignally it is 0x32--0011 0010
    cnt_r2 |= 1;
  if(cnt_r2)
    {
      if(k2==1)
        {
          receive_r2[1] = UCA0RXBUF & 0x3F;  //--for the T2 1011 0010 -- 0xB2
          k2++;
        }
          t2++;  //jump out for this turn, when t2=3, the value of the BUF will again to send its value
      if(t2>=3)
        receive_r2[k2++] = UCA0RXBUF;
      if(k2 == sizeof (receive_r2) -1)
        {
          P1OUT = P1OUT^BIT6;
          k2=1;
          t2=1;
          cnt_r2 &= ~1;
          count_r2|=1;
        }     
    }
 
  if(UCA0RXBUF==0x54)  //--T(1), 0101 0100 0x54
    receive_t1[0] = UCA0RXBUF;
  if(UCA0RXBUF == 0x71)  //--for the T1 0111 0001, orignally it is 0x31--0011 0010
    cnt_t1 |= 1;
  if(cnt_t1)
    {
      if(k3==1)
        {
          receive_t1[1] = UCA0RXBUF & 0x3F;  //--for the T1 0111 0001 -- 0x71
          k3++;
        }
          t3++;  //jump out for this turn, when t4=3, the value of the BUF will again to send its value
      if(t3>=3)
        receive_t1[k3++] = UCA0RXBUF;
      if(k3 == sizeof (receive_t1) -1)
        {
          P1OUT = P1OUT^BIT6;
          k3=1;
          t3=1;
          cnt_t1 &= ~1;
          sd_tb1 |= 1;
          count_t1|=1;
        }     
    }
 
    
  if(UCA0RXBUF==0xD4)  //--T(2), 0101 0100 0x54 --> 1101 0100 0xD4
    receive_t2[0] = UCA0RXBUF & 0x7F;
  if(UCA0RXBUF == 0x72)  //--for the T2 0111 0010, orignally it is 0x32--0011 0010
    cnt_t2 |= 1;
  if(cnt_t2)
    {
      if(k4==1)
        {
          receive_t2[1] = UCA0RXBUF & 0x3F;  //--for the T2 0111 0010 -- 0x72
          k4++;
        }
          t4++;  //jump out for this turn, when t4=3, the value of the BUF will again to send its value
      if(t4>=3)
        receive_t2[k4++] = UCA0RXBUF;
      if(k4 == sizeof (receive_t2) -1)
        {
          P1OUT = P1OUT^BIT0;
          k4=1;
          t4=1;
          cnt_t2 &= ~1;
          count_t2|=1;
        }     
    }
}



Best Regards

  •  Hi, I read your post but I need say is completely unreadable....
     From the quote following I can imagine you are converting something from other:

    Yuan Liao said:

    I'm new to the msp430FG4619 chip, and now I am doing the project which needs to use uart mode to get the data from the radar and send it to the sd card, but at the same time the collected time should be accurate to the millisecond.

    However, the fg4619 chip doesnt have the millisecond part, so I need to use timer module to synchronize with the RTC second part. But after I am facing with more complicated problem, I need to do accurate as much as I can among the uart mode, timer module and SD writing...It means they should be synchronized..I think it is hard to achieve, cause I need to manage the whole structure of the code, but  I am a freshman in this area...

     Are you using a RADAR or an SONAR? From some of your wording I suppose you are adapting a sonar module and an Arduino example... May be you get more succes if you use your IDE in Energia mode porting code as is.

     If you need a timer in millisecond range it can be simply derived from one interrupting at 1mS or less then counting down a variable.

     If you are using a sonar module HC-SR04 (PING ECHO pin) a better measure can be obtained measuring pulse width using capture than a simple timer.

     Never do delay in the interrupt, set a flag and process on main. If timing are to be accurate to uS then use capture module, service interrupt to read then again process in main background.

  • Hi Roberto,


    thanks for your reply. I'm sorry for my writing which is not clear to you. I didnt convert some other's words into my writing. I'm using radar to send data to my msp430fg4619. because the speed of the transmission in radar is every 10 milliseconds, so I'm wondering how could make the time more accurate. in the UART interrupt, the code is to differentiate the data it received, so I just think is there any better solution to minimize it, cause it is really to much, and it may cause the time drift when I write to the sd card. 

    thanks so much for your time.

    Best regards

  • Roberto Romano said:
     Hi, I read your post but I need say is completely unreadable....



    yes you are right Roberto. I code is almost impossible to read. and also lots of t's, k,s etc.

    Yuan it is advisable to use syntax highlighter while posting code. Copy the code, clcik on syntax highlighter and paske. hit insert and the code is presented in the best possible way.

    Also while coding it is advisable to use, readable names like.
    int  Radar_range;
    int   delay_time_between_pulses;

    etc.

  • Thanks so much, I just realized that... I repost it to the forum, and you try to update it, I think it is readable now. thanks so much for your suggestion

  • Yuan Liao said:
    Thanks so much, I just realized that... I repost it to the forum, and you try to update it, I think it is readable now. thanks so much for your suggestion

     Again are you using a RADAR or a SONAR, ultrasound transmitter and receiver like this:

    http://www.parallax.com/product/28015?SortField=ProductName,ProductName

     from your timing off mS range i suppos this,

    or a RADAR like this

    http://digipak.org/zencart/index.php?main_page=product_info&products_id=78 ???

     This last case hardware resolution in short range is less than you can do and just high speed MSP430F5xx series can provide sub 1m resolution, in the case of USonar, the best can be remove hardware and use two ultrasound  transducer directly driven from MSP, do precise pulse and detect from MSP Capture than reading inaccurate return pulse from slow PIC on board...

     If you explain more we can help.

**Attention** This is a public forum