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.

communicating with computer

Other Parts Discussed in Thread: MSP430FG4619

hi

well i am working on a project which involves sending and receiving data from a microcontroller. for this i have written a simple code in which the microcontroller is sending a byte of data to the computer, but when i try viewing the data in hyperterminal nothing is being displayed, instead whatever i type is just getting echoed from the microcontroller. i am using a MSP430FG4619, the board i am using has an usb interface(picture of test board uploaded). the code that i have written to just send some bytes to pc is :


#include <msp430FG4619.h>

void main(void)
{
volatile unsigned int i;

WDTCTL = WDTPW+WDTHOLD;
FLL_CTL0 |= XCAP14PF;
P4SEL |= 0xC0;

do
{
IFG1 &= ~OFIFG;
for (i = 0x47FF; i > 0; i--);
}
while ((IFG1 & OFIFG));

ME2 |= UTXE1 + URXE1;
U1CTL |= CHAR;
U1TCTL |= SSEL1;
U1BR0 = 0x09;
U1BR1 = 0x00;
U1MCTL = 0x08;
U1CTL &= ~SWRST;
IE2 |= URXIE1 + UTXIE1;

}

#pragma vector=USART1RX_VECTOR
__interrupt void USART1_rx (void)
{
while (!(IFG2 & UTXIFG1));
TXBUF1 = 0x42;
}

since i am new to this i didnt know much about it, just wrote this code seeing some examples. 
can anyone find out what's wrong with this code?? or is there some other way to go about this??
thanks in advance!!

  • Hello,

    I just wrote an answer to a similar problem. Maybe you can have a look at it.

    http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/t/176701.aspx#636213

    On the first look I would say you should configure the Digital I/O Ports correctly for usage with USART.

    See the Digital I/O section of the User's Manual for your MSP430.

    Regards Marco

  • Hi,

    I quick couple of things that I see is that you have enabled the receive and transmit interrupts for USART1, but you haven't enabled the global interrupt (GIE).  Another issue I see is that when you do enable the GIE, you have an ISR for the receive interrupt but you don't have one for the transmit interrupt.

    HTH,

    Barry

  • hi Marco

    thanks for replying 

    well i have gone through the datasheet of the controller, it says that when in usci mode the pin 4.6 is set to output and pin 4.7 is set to input automatically. so by the P4SEL statement i selected them to work in usci mode.

  • hi Barry

    thanks for replying

    well understood what you tried to say, so i addend another line in the code

    _BIS_SR(GIE);

    well i think this enables the GIE interrupts, but still the problem persists. i am not getting anything from the microcontroller in the hyperterminal, instead whatever i type is just getting echoed

  • Akash,

    One other thing to point out is that you need a while(1) or for(;;) loop or a low power mode to enter at the end of main to maintain debug stability.

    Otherwise your instruction pointer will exit main and execute the __system_pre_init() and __nop() functions after exiting main.

    I am also wondering if you have something like the following enabled in the hyperterminal that you are using:

  • Akash,

    I also recommend have a look at our most recent code examples for the MSP430FG4619.

    MSP430FG461x Code Examples (Rev. D): http://www.ti.com/litv/zip/slac118d

    USCI_A0_UART @ 115200 baud:


    #include  <msp430xG46x.h>
    void main(void)
    {
      volatile unsigned int i;

      WDTCTL = WDTPW+WDTHOLD;                   // Stop WDT
      FLL_CTL0 |= XCAP14PF;                     // Configure load caps

      do
      {
      IFG1 &= ~OFIFG;                           // Clear OSCFault flag
      for (i = 0x47FF; i > 0; i--);             // Time for flag to set
      }
      while ((IFG1 & OFIFG));                   // OSCFault flag still set?

      P4SEL |= 0x0C0;                           // P4.7,6 = USCI_A0 RXD/TXD
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 0x09;                           // 1MHz 115200
      UCA0BR1 = 0x00;                           // 1MHz 115200
      UCA0MCTL = 0x02;                          // Modulation
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt

      _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0, interrupts enabled

    // while(1)                                               // instead of LPM0_bits
    }

    //  Echo back RXed character, confirm TX buffer is ready first
    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCIA0RX_ISR (void)
    {
      while(!(IFG2&UCA0TXIFG));
      UCA0TXBUF = UCA0RXBUF;                    // TX -> RXed character ***Change this to 0x42***
    }

  • akash satapathy said:
    i am not getting anything from the microcontroller in the hyperterminal, instead whatever i type is just getting echoed

    Either you have local echo option enabled. So everything you type, is just shown on screen, but the MSP never receives it.
    Or the code on teh MSP isn't the code you posted.

    The original demo code has the line
    TXBUF1 = RXBUF1;
    where you have
    TXBUF1=0x42;
    And this would exactly do what <ou experience: echoing everything.

    What your code should do is: when an RX interrupt is received, the code waits for TXBUF ebing clear, then it sends 0x42 ("B"). Then the ISR exits, and because you didn't clear the RXIFG bit (you never read RXBUF1 or manually clear the IFG bit). the ISR is executed again immediately. And again. And again....

    So after the first keypress, you should see an endless line of 'B's. Whcih you don't.

    So one of two things (or both) happen:

    1) local echo is on and the MSP is deaf and silent. Which could be because of a faulty physical connection (how did you connect the MSP to the PC? With a proper level shifter? The MSP requires RS232 signals, the MSP TTL signals. Is MSP TX connected with PCs RxD adn MSPs RX with PCs TxD?)

    2) you never uploaded your modified software to the MSP but run it in simulator instead. So the original demo software is still running on the MSp, echoing everything that comes in.
    If the demo was an imported project and you started a new one for the modified code, the new project maybe is still configured to use teh simulator, not the emulator. (I wonder why this is still called 'emulator' when it actually uses the real MSP - so much cause for confusion! Well, FET means Flash Emulation Tool, but it doesn't emulate flash at all for the last many years now )

**Attention** This is a public forum