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.

Trouble getting hardware UART to work

Other Parts Discussed in Thread: MAX3232, MSP430G2553

Hi everyone,

I'm trying to implement hardware UART into my project and so I thought I'd get started by writing some basic test code. I've been trying to get hardware UART transmit to work but have been having issues.

So far, I've just been trying to get data to at least transmit but to no avail. My setup is that I am using a MSP430 launchpad with a MSP430g2553 MCU. I connected the jumpers on the board for hardware UART. I also connected the RXD line on the launchpad (1.1) to the RXD pin on a MAX3232 board and the TXD line (1.2) of the launchpad to the TXD pin of the MAX3232 board. Of course, VCC and GND is hooked up to the MAX3232 as well. I then connect an RS232 cable from my PC to the MAX3232 board so it can connect to the microcontroller. 

But when I run my code, nothing gets transmitted. This is my first doing hardware UART and I had lots of trouble finding decent sources online for doing HW UART on the MSP430. 

If anybody who is more well versed in hardware UART can provide any help or corrections to my work, I would really appreciate it!

This is my current code:

#include <msp430g2553.h>

int main(void)
{
UCA0CTL1 |= UCSWRST;

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation

P1SEL |= BIT1 + BIT2; //select RXD and TXD for UART
UCA0CTL0 |= UCMSB; //start MSB and UART mode
UCA0CTL1 |= UCSSEL_3;
UCA0MCTL = 0;
UCA0BR0 = 0x68; //104 9600Buad 1MHz clock
UCA0BR1 = 0x00;
//IE2 |= UCA0RXIE;
//IFG2 |= UCA0TXIFG + UCA0RXIFG;

UCA0CTL1 &= ~UCSWRST; //toggle swreset off

while (1)
{
UCA0TXBUF = 0x41;
//while ((UCA0STAT & UCBUSY)==0x01)
while (!(IFG2 & UCA0TXIFG));
_delay_cycles(100);
}
}

Thanks,
Tony
  • HEllo,

    i just read through really fast, first thing that comes to my mind is, are you sure with your connection between RS323 converetr and MSP430? normally one should connect RX to TX and vice versa. Perhaps already there is your problem, but i guess you connected right and wrote wrong, as this happens to me a lot of times too.

    can you check your uart output pin with an oscilloscope? when you write 0x41 to it you should be able to see that at this pin, so you might now where the error happens, like in the MSP430 or outside at your RS232 converter or PC.

    Next thing is your UART init, are you sure you selected UART mode, I didnt read your familyguide nor datasheet, but

    UCA0CTL0 |= UCMSB; //start MSB and UART mode
    this seems a little short, when i compare it to my register settings, could be right though.

    Hope this will help a bit.
    Greetings
  • Thanks for the reply!

    Based on the schematic for the MAX3232 board I used ( http://microcontrollershop.com/product_info.php?products_id=4169), the RX pin is an output and the TX pin is an input. So therefore, I'm pretty sure I connected it right since RXD connects to RX in order to receive data from the output of the board and TXD connects to TX in order for the MAX3232 to receive input from the microcontroller to send to the PC.

    I'll go ahead and check use an oscilloscope to check if anything was sent and report with any results. I'm pretty sureUART mode is selected by default? Or should I write:

     UCA0CTL0 |= UCMSB + UMODE_0;   ???

  • Just to the last thing

    Anthony Lee said:

    UCA0CTL0 |= UCMSB + UMODE_0;   ???

    I think, after 1 year of coding for myself, it is always better to set every bit and comment what you do, so you minimize wrong settings, and after some month in a new project it is way easier to find back into some old code.

    But I agree, most of the times some settings are good in default mode, but setting them anyway wont hurt you or the code, but increase readability.

  • Anthony Lee said:
    P1SEL |= BIT1 + BIT2; //select RXD and TXD for UART

    Not quite. This alone sets the pins for TA0.0/TA0.1
    You'll need to set P1SEL2|=BIT1|BIT2; too
    (ORing bits is better than ADDing them - it not only expesses the intention of settign bits ratehr than adding values, it also avoids complications when both terms share some bits, as it sometimes happens with soem convenience-defines, e.g. for different WDT modes etc.)

**Attention** This is a public forum