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.

MSP430G2553 communicating with LabVIEW via a RS232 to USB cable. The communication is UART. LabVIEW receives wrong characters.

Other Parts Discussed in Thread: MAX3232

Im communicating to LabVIEW with an MSP430G2553 microcontroller through UART.  The connection is a Sabrent CB-RS232 cable.  The USB end is going to the computer.  LabVIEW only needs to read in values.  I've tried a 9600 and then a 256000 baud rate.  I'm sending the same char value over and over from the MSP430.  The chars that LabVIEW reads in are always different.  For instance if I send a 'J' the buffer will show 'k'.  It will then say '\A9' or something else if I stop LabVIew and run it again.

Everything works fine if I use the USB connection on the Launchpad.  Here's the code I'm using:

#include <msp430.h>

volatile unsigned char testbuf;

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 | UCPEN | ~UCPAR; // SMCLK

UCA0BR0 = 104; // 1MHz 9600

UCA0BR1 = 0x00; // 1MHz 9600

UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1

UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**

UC0IE |= UCA0TXIE; // Enable USCI_A0 RX interrupt

ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled

ADC10CTL1 = INCH_4; // input A1

ADC10AE0 |= 0x10;

testbuf = 'H';

while(1)

{

ADC10CTL0 |= ENC + ADC10SC;

UCA0TXBUF = testbuf;

}

}

#pragma vector=USCIAB0TX_VECTOR

__interrupt void USCI0TX_ISR(void)

{

while (!(UCA0TXIFG)); // USCI_A0 TX buffer ready?

}

Does anyone have any ideas?

  • John Williams2 said:
    The connection is a Sabrent CB-RS232 cable.

    What output signal type does this cable generate? The name seems to indicate that it will output RS232 signals.
    RS232 signals use -15V to -3V for 'high' and 3 to 15V for 'low'. The MSP, however, uses 0V for low and VCC for high (TTL level). Directly connecting the MSP's TX and RX lines to an RS232 singal may permanently damage the chip. But at the very least, it won't work, as the 'high' level of the MSP is a clear 'low' for RS232. (and the MSP 'low' is an invalid voltage on RS232)
    You'll need a TTL/RS232 level shifter like the MAX3232.

    Besides this, your ISR won't work. First, when the ISR has been called, this means that TXIFG is set, indicating that the UART output buffer is ready to take the next byte. SO waiting inside the ISR for TXIFG is superfluous at best. But then your ISR needs to handle this interrupt. That means, you either clear TXIE (no more interrupts), clear TXIFG (ignore the current one) or write something to TXBUF inside the ISR. Or the ISR will be called over and over again and main stops executing (0% CPU left)

    Finally, your main code constantly (within microseconds) starts a new conversion (while the last one is still running) and writes to TXBUF (while it is still full, or else the ISR would be called).

    Well, this code is never executed anyway, because in the very moment you set TXIE, the ISR gets called, and called, and called...

  • Thank you Jens-Michael!  The MAX3232 solved the issue.

**Attention** This is a public forum