简体   繁体   中英

MSP430 UART unwanted loopback with Raspberry Pi

So I'm having a problem getting a TI microcontroller to communicate with the Raspberry Pi B+. The exact microcontroller I'm using is the TI cc430f5137. The issue I'm having is that I just can't seem to get the Raspberry Pi to correctly receive the data I'm sending from the MSP430. For those who don't know, the 430 has 2 buffers for this purpose, a RX and TX, which allows the use of the UART module while code is still executing. I've enabled an interrupt for when I receive a byte, and I simply set a flag and send the same byte right back. It works up until I attempt to transmit. The code sits and waits in an infinite loop until it receives it's first byte. At that point it simply saves the byte and flashes the LED if it's a 'T' (for testing). Upon returning to the loop, it detects that the saved byte has changed, and puts it in the buffer to send it back. Until this point, everything works perfectly. It receives the correct byte every time, letting me know my clocks are perfect, my interrupt is working, and my UART initialization is correct. Where it goes wrong is after sending the byte, it seems like there is some kind of internal loopback (this is an option but I made sure this is not the case) that is causing the interrupt to re-trigger, resulting in an infinite loop of transmitting and again receiving the same byte, but upon invoking this via the Pi I don't get back a loop of the same character, but instead a byte of random garbage that has no consistency or logic behind it. I analyzed the bits to see if the timing is just off and that doesn't seem to be the case. For reference, my Baud is a measly 1200, the voltage of both devices is definitely 3.3v, and I'm sure the Pi is working because when I short the RX and TX, I get back the byte without an issue. I switched to UART because SPI was giving me similar problems, and I can't think of any other protocol besides I2C that would help here. I am using an external 32768hz crystal. Also, I've tried this on two different microcontrollers, so its definitely the code that's the issue.

#include <msp430.h> 

char temp;
char in;


int main(void) {
    WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer

    P1OUT = 0x00; // Make sure pins are tturned off
    P1DIR = 0x01; // Led out
    P1SEL |= BIT5 + BIT6; // UART as pin mode

    UCSCTL6 &= ~BIT0; // Turn on XT1

    P5SEL |= BIT0 + BIT1; // Select XT1 as pin function

    UCA0CTL1 |= BIT0; // Set UART to reset mode
    UCA0CTL1 |= BIT6; // Choose ACLK as source

    UCA0BR0 = 27; // Set speed to 1200 Baud
    UCA0MCTL = 0x02 << 1; // Set speed to 1200 Baud

    UCA0CTL1 &= ~BIT0; // Turn UART on

    UCA0IE = BIT0; // Enable RX interrupt
    __enable_interrupt();

    while(1)
    {
        if(in != 0)
        {
            UCA0TXBUF = in;
            temp = in;
            in = 0;
        }
    }
}

#pragma vector=USCI_A0_VECTOR
__interrupt void UCSIA0(void)
{
    in = UCA0RXBUF;
    if(in == 0x54)
        P1OUT ^= BIT0;
} 

Output from running minicom at 1200 on Pi, Sending 'T' one at a time:

UÔÿÿïÕuU_þýÿÿÿÿÿÿÕԯÿÿôÕüÿÝUõï\þþÿÿÕ¿ÿÿýýTÿýUÿÿÿïÿÿÿõÿýýÿõûÿ

assuming Pi is working currectly...

1.verify msp430 TX is woring: send every 1 sec known value and see if PI getting it currectly.

2.verify MSP430 RX working: send from Pi known value every 1 sec.

3.interrupt section:

  • your code dosent verfiy that RX interrupt is off.
  • you should filter interrupts generated only for the RX .
  • also, your code dont handle overrun/frame errors.
  • sharing "in" variable both for TX and RX (and both at interrupt and main loop section)-not good idea..

4.your output example suggests that you have baud rate mismatch issue. if you send character 'T' and shoud get back 'T'. i expect to see 'TTTTTT...' BTW this garbage may suggests that you forgot to connecting GND line between two MCUs...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM