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 not transmitting

Other Parts Discussed in Thread: MSP430G2553, MSPWARE, MSP430WARE

Hi,

Im trying to use my 3.3v FTDI cable to display ADC values from my MSP430 G2553 in hyperterminal.

Im only using the RX of the UART P1.2

Ive been stepping through the program and all three ADC readings are taken stroed in three different variables but when it comes to transmitting the program seems to be getting stuck in a loop here: while (!(IFG2&UCA0TXIFG));

I get nothing out to hyperterminal because of this

Its part of the recursive function to get around the 10 bit ADC to 8 bit UART problem.

this is the recursive function for reference.
void UART_OutUDec(unsigned long n)
{
  //  This function uses recursion to convert decimal number
 //   of unspecified length as an ASCII string
  if(n >= 10)
  {
    
      UART_OutUDec(n/10);
      n = n%10;
  }
   while (!(IFG2&UCA0TXIFG));
   UCA0TXBUF=(n+'0'); /* n is between 0 and 9 */

thanks guys

  • Can you show your complete code including the port configuration?
  • Hi again Dennis,
    Yes sorry I should have included that.
    Here it is below.
    its a voltage divider circuit.

    p1.0 is connected after R1=100ohms
    P1.1 is connected after R2=1K thermistor
    p1.2 is being used for UART RX -EDIT: I meant  TX
    p1.3 is connected after R3 =1k
    and a final resistor going to ground

    So its VCC (from the msp Dev board to my breadboard) > R1>R2>R3>R4>GND (from the Dev board)
    p1.2 is connected to the TTL 3.3V serial cable at its RXD yellow pin with a common GND from the breadboard from the MSP Dev board.



    #include "msp430g2553.h"
    //#define r1 100; use later for temp conversion
    #define r1 1000; //USED LATER FOR OUTPUT TEMP. CALCULATION

    unsigned int Top, Middle, Bottom; //ADC RESULT VARIABLES
    void Read_Value(int A);
    void UART_OutUDec(unsigned long n); //RECURSION FUNCTION

    int main(void)
    {

    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    if (CALBC1_1MHZ==0xFF) // If calibration constant erased
    {
    while(1); // do not load, trap CPU!!
    }
    DCOCTL = 0; // Select lowest DCOx and MODx settings
    BCSCTL1 = CALBC1_1MHZ; // Set DCO
    DCOCTL = CALDCO_1MHZ;
    P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
    P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
    UCA0CTL1 |= UCSSEL_2; // SMCLK
    UCA0BR0 = 104; // 1MHz 9600
    UCA0BR1 = 0; // 1MHz 9600
    UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
    UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
    IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt





    while(1)
    {
    Read_Value(1); //setup for ADC P1.0
    Read_Value(2); //setup for ADC P1.1
    Read_Value(3); //setup for ADC P1.3
    //add in temp conversion


    UART_OutUDec(Top); //TX TOP RESULT
    UCA0TXBUF = 0X09; //TAB
    UART_OutUDec(Middle); //TX MIDDLE/THERMISTOR RESULT
    UCA0TXBUF = 0X09; //TAB
    UART_OutUDec(Bottom); //TX BOTTOM RESULT
    UCA0TXBUF = 0X09; //TAB
    while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
    UCA0TXBUF = 0X0A; // NEW LINE
    }
    }
    void Read_Value(int A)
    {

    ADC10CTL0=0x00; // Stop ADC
    if(A==1)
    {
    ADC10CTL1=INCH_0+ ADC10SSEL_3; // Input Channel A0 and SMCLK
    ADC10AE0=0x01; // Enable analog input for p1.0
    }
    if(A==2)
    {
    ADC10CTL1=INCH_1+ ADC10SSEL_3; // Input Channel A1 and SMCLK
    ADC10AE0=0x02; // Enable analog input for p1.1
    }
    if(A==3)
    {
    ADC10CTL1=INCH_3+ ADC10SSEL_3; // Input Channel A3 and SMCLK
    ADC10AE0=0x08; // Enable analog input for p1.3
    }

    ADC10CTL0= ADC10ON + ENC; // Turn on ADC and Enable Conversion
    ADC10CTL0=ADC10CTL0 | ADC10SC; // start conversion

    while(ADC10CTL1 & ADC10BUSY) // wait until conversion is complete
    {
    }
    if(A==1)
    {
    Top=ADC10MEM; // ADC VALUE top_R100
    }
    if(A==2)
    {
    Middle=ADC10MEM; // ADC VALUE Middle/ 1k Thermistor
    }
    if(A==3)
    {
    Bottom=ADC10MEM; // ADC VALUE Bottom_R100K
    }
    }




    //}
    void UART_OutUDec(unsigned long n)
    {
    // This function uses recursion to convert decimal number
    // of unspecified length as an ASCII string
    if(n >= 10)
    {

    UART_OutUDec(n/10);
    n = n%10;
    }
    while (!(IFG2&UCA0TXIFG));
    UCA0TXBUF=(n+'0'); /* n is between 0 and 9 */
    }

  • Hi James!

    Thanks for uploading everything. I have no more time today - it is already evening here in Germany, but I can have a closer look at your code tomorrow (and test it if necessary). But maybe anyone else figured out your problem until tomorrow already.

    Dennis
  • Hi Dennis,
    Thanks for your help,
    Thank you for looking I appreciate it.
  • Hi James,

    I made some changes to your program:

    #include "msp430g2553.h"
    
    
    
    unsigned int Top, Middle, Bottom;      // ADC RESULT VARIABLES
    
    void Read_Value( int A );              // Read ADC values
    void UART_OutUDec( unsigned long n );  // Convert result to ASCII decimals
    void UART_output( char data );         // Output UART data
    
    
    
    int main( void )
    {
      WDTCTL = (WDTPW | WDTHOLD);          // Stop WDT
    
      if( CALBC1_1MHZ == 0xFF )            // If calibration constant erased
      {
        while( 1 );                        // Do not load, trap CPU!!
      }
    
      DCOCTL    = 0;                       // Select lowest DCOx and MODx settings
      BCSCTL1   = CALBC1_1MHZ;             // Set DCO
      DCOCTL    = CALDCO_1MHZ;
    
      P1SEL     = (BIT1 | BIT2);           // P1.1 = RXD, P1.2 = TXD
      P1SEL2    = (BIT1 | BIT2);           // P1.1 = RXD, P1.2 = TXD
    
      UCA0CTL1  = UCSWRST;                 // USCI reset
      UCA0CTL1 |= UCSSEL_2;                // SMCLK
      UCA0BR0   = 104;                     // 1MHz 9600
      UCA0BR1   = 0;                       // 1MHz 9600
      UCA0MCTL  = UCBRS0;                  // Modulation UCBRSx = 1
      UCA0CTL1 &= ~UCSWRST;                // Release USCI from reset
      IE2      |= UCA0RXIE;                // Enable USCI_A0 RX interrupt
    
      while( 1 )
      {
        Read_Value( 1 );                   // Setup for ADC P1.0
        Read_Value( 2 );                   // Setup for ADC P1.1
        Read_Value( 3 );                   // Setup for ADC P1.3
        //add in temp conversion
    
        UART_OutUDec( Top );               // TX TOP RESULT
        UART_output( 0x09 );               // TAB
        UART_OutUDec( Middle );            // TX MIDDLE / THERMISTOR RESULT
        UART_output( 0x09 );               // TAB
        UART_OutUDec( Bottom );            // TX BOTTOM RESULT
        UART_output( 0x09 );               // TAB
        UART_output( 0x0A );               // NEW LINE
      }
    }
    
    
    
    void Read_Value( int A )
    {
      ADC10CTL0 = 0x00; // Stop ADC
    
      if( A == 1 )
      {
        ADC10CTL1 = INCH_0 | ADC10SSEL_3;  // Input Channel A0 and SMCLK
        ADC10AE0 = 0x01;                   // Enable analog input for p1.0
      }
    
      if( A == 2 )
      {
        ADC10CTL1 = INCH_1 | ADC10SSEL_3;  // Input Channel A1 and SMCLK
        ADC10AE0 = 0x02;                   // Enable analog input for p1.1
      }
    
      if( A == 3 )
      {
        ADC10CTL1 = INCH_3 | ADC10SSEL_3;  // Input Channel A3 and SMCLK
        ADC10AE0 = 0x08;                   // Enable analog input for p1.3
      }
    
      ADC10CTL0 = ADC10ON | ENC;           // Turn on ADC and Enable Conversion
      ADC10CTL0 = ADC10CTL0 | ADC10SC;     // Start conversion
    
      while( ADC10CTL1 & ADC10BUSY )       // Wait until conversion is complete
      {
      }
    
      if( A == 1 )
      {
        Top = ADC10MEM;                    // ADC VALUE top_R100
      }
    
      if( A == 2 )
      {
        Middle = ADC10MEM;                 // ADC VALUE Middle/ 1k Thermistor
      }
    
      if( A == 3 )
      {
        Bottom = ADC10MEM;                 // ADC VALUE Bottom_R100K
      }
    }
    
    
    
    void UART_OutUDec( unsigned long n )
    {
      UART_output( (n / 1000) + '0' );
      n %= 1000;
      UART_output( (n / 100) + '0' );
      n %= 100;
      UART_output( (n / 10) + '0' );
      UART_output( (n % 10) + '0' );
    }
    
    
    
    void UART_output( char data )
    {
      while( !(IFG2 & UCA0TXIFG) );
      UCA0TXBUF = data;
    }

    Please try it and have a look if it works as expected. Then we can discuss it if you want.

    Dennis

  • Hi Dennis,

    Thanks for your revised code,

    I tried it in a new project and it compiles with no errors. Ive been stepping through the code but it seems to have the same issue where its always in the loop for the uart IFG interrupt.

    I tried clicking about  100 times on the debugger but it never leaves the loop.

    I cant see anything on hyperterminal, and Ive tried the arduino serial monitor just in case its a windows 10 issue.

    The drivers for the ftdi cable are installed and its a ttl 3.3v cable, Ive even tried powering the MSP430 launchpad with the Vout of the FTDI cable and removing the MSP430 usb cable in case there was some sort of conflict.

    I am not sure if its a hardware setup problem or a software one.

    Thanks for all your help so far Dennis.

  • James,

    then please check your hardware or settings for the baudrate / COM-port on the PC side. It runs on my LaunchPad and sends the values to the PC.
    Do you have a MSP-EXP430G2 with hardware UART? Please try the application UART in that case. Maybe your connection to the FT232 is wrong?

    Dennis
  • James Woodrow said:
    where its always in the loop for the uart IFG interrupt

    Which one do you mean? Can you post the line number? Do you have optimizations completely turned off for debugging? Right-click on your project in the resource explorer and select properties, then go to optimization and switch it off.

    Is there anyone else that can test the code with a terminal program?

    Dennis

  • Hi Dennis,
    I have hyper terminal set as 9600 baud, data bits 8, parity: none, stop bits 1, flow control: none
    The yellow (RXD) of the ftdi is connected to P1.2 (UART TX) there is a common ground black from the ftdi between the breadboard and launchpads GND. The FTDI Vout(Red) is connected to to the breadboard and VCC of the Launchpad and is powering it and the resistor circuit.
    Ive also got the jumpers removed from P1.0 and p1.6 so the LED's are connected, but P1.6 isn't being used but I have removed the jumper anyway.

    Ive disabled optimizations in the C/C++ compiler  and its set at none from 'low'

    My EXP430G2 has the hardware UART

    The line it gets stuck at is 118,

    I try to repeatedly step into it but it never continues.


    Thanks

  • Can you then check the code with the hardware UART instead of your FTDI adapter first? Make sure the jumpers on the LaunchPad are set correctly and look what COM-port the application UART got.
  • In my code I found a line that you can delete (but this has nothing to do with your problem):

    n %= 10;

    I've changed it in my posted code lines.

    Dennis

  • Hi Dennis,
    The UART/USB cable of the msp 430 is on port 23, I even tried a new launchpad out of the box, it programmed fine but it seems like the same thing. I have the MSP430 running continuously outside of IAR, and tried hyperterminal again but it never does anything, baud is still 9600 and the comport is 23.
    thanks
  • Now with the application UART of the LaunchPad?
  • As in selecting COM 23, MSP430 APPLICATION UART, it does the same thing.
    I set up hyperterminal, selected COM23, 9600 BAUD but nothing appears.
    Its odd, You'd think something would appear, I would imagine that the ADC would pick up something even if there was a breadboard wiring issue and transmit something to Hyperterminal
    Its very odd
  • The ADC picks up any crap from the surrounding. In my tests I did not connect anything to the analog inputs and of course got values anyway. Do you have an oscilloscope to measure TX? Are your jumpers on the LaunchPad placed 90° in orientation? Your terminal is connected to the COM-port? For testing: Short P1.1 and P1.2 and then send something from the PC and see if it is echoed back through the application UART. But make sure that the MSP does not drive TX during that test. So a) comment out the port initialization so the pins are both inputs or b) remove the MSP.

    I used HTerm, but there shouldn't be a difference between the different terminal programs.

    Dennis
  • I put the jumpers 90 degrees so now its HW UART mode.
    Ive also removed the msp430 and tried shorting p1.1 and p1.2,
    I tried arduino serial monitor but trying to echo something or send a character crashes the program, the same occurs in Hyperterminal
  • I do not know the Arduino Serial Monitor and I never used Hyperterminal, but with the jumpers placed in 90° of orientation and then connect P1.1 and P1.2 together with the MSP removed, the PC should receive any character it sends back. If that does not work, then the issue is not in the program.
  • Could you test another terminal program or rename the COM-port? I know from some programs that do not work with higher COM-port numbers. Maybe that is the issue.

    You can try HTerm:

    It runs without installation.

    Dennis

  • Don't give up James! At the end...it will work!
  • Hmmm, Ive tried with no msp430, it still doesn't do anything
    I tried running the same on a Windows 7 machine and it still not working.
    I shorted rx/tx on the ftdi cable and that echoes back on the windows 7 machine.
    I dont know what it could be.
    Its probably something really stupid or simple
  • It seems to still be stuck on the void_UART_output() function just before transmitting.
    while( !(IFG2 & UCA0TXIFG) ); this line, I removed the ; at the end and it goes to the next line where it transmits the char data but it just stays there no matter how many step intos i take.
  • If you just let the program run, does the PC receive nothing?
  • Yeah, if i download the code, exit IAR workbench, pull out and reconnect the usb for the launcpad and try hyperterminal the same thing happens where nothing is received.
  • That's strange! It runs without problems here. ;/
  • The TTL FTDI cable is a 3.3v logic cable and still does nothing when I have nothing else connected top the port pins other than the FTDI cable.
    My hyperterminal is set to read a 9600baud, 8 bits, no parity, 1 stop bit.
    its very odd and I haven no idea why its doing this on both board too.
    all i wanted it to do was read the and send ADC values to hyperterminal, its not a big ask either lol why ever it doesnt work.
    Im using the msp430g2553 header file too,
  • hmm.. i think the problem may be the setup of the MSP430 IAR program, It seem that when i pulled out my new MSP430 with led blink installed and tried to download the code to the device it went to the debug/simulate window where i can step through the code but it doesnt appear to be actually installed on the msp430 device. any ideas

  • Now you're lucky James, there is no problem OCY cannot solve ;)
  • Hello James,

    there seems to be a few potential points of failure here in the communication chain. Let's take a step back and see what we can get working in order to narrow down the issue. You are using a MSP430G2553 Launchpad correct? If so can you load the example code provided with MSP430Ware titled  msp430g2xx3_uscia0_uart_08_9600.c  (USCI_A0, UART 9600 Full-Duplex Transceiver, 32kHz ACLK) ? If you do not have MSPWare downloaded on your computer, please checkout CCSCloud or our Cloud Resource Explorer to quickly download this example to your device.  From this example, let's change the clock settings and subsequent UART Baud Settings to fit with what you are doing with your code. This is assuming you are not using an LF XTAL for ACLK.  Make sure to have the jumper settings to HW UART mode and connect device directly to your PC via USB. This should work with any terminal program once you point it to the MSP430 Application UART. Once your PC has valid communication with the LP, we can rule out the PC and its programs the cause of your issue here. From there, let's remove the jumpers and USB cable and place your TTL Cable setup with the same example SW on the MSP430. If this fails, we have an issue with the TTL Cable setup, if it succeeds then we need to concentrate on your original code.

    Please post back with your questions or results.

    Regards,

    JH

  • Hi,
    Sorry I should have mentioned I eventaully got the code downloaded to the MSP430
  • James,

    Does this mean your original issue is solved?

    Regards,
    JH
  • Yes, Thankfully with great thanks to you guys!!
  • So the code works for you now as well?

**Attention** This is a public forum