简体   繁体   English

Raspberry Pi的MSP430 UART有害回送

[英]MSP430 UART unwanted loopback with Raspberry Pi

So I'm having a problem getting a TI microcontroller to communicate with the Raspberry Pi B+. 因此,让TI微控制器与Raspberry Pi B +通信时遇到了问题。 The exact microcontroller I'm using is the TI cc430f5137. 我使用的确切的微控制器是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. 我遇到的问题是,我似乎无法让Raspberry Pi正确接收我从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. 对于那些不知道的人,430为此有2个缓冲区,即RX和TX,允许在代码仍在执行时使用UART模块。 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). 那时,它只是保存字节,如果它是“ T”(用于测试),则使LED闪烁。 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. 每次它接收到正确的字节,让我知道我的时钟是完美的,我的中断正在工作,并且我的UART初始化是正确的。 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. 发生错误的地方是在发送字节之后,似乎存在某种内部环回(这是一个选项,但我确定不是这种情况),这会导致中断重新触发,从而导致无限循环传输并再次接收相同的字节,但是通过Pi调用该字节时,我不会返回具有相同字符的循环,而是返回了一个随机垃圾字节,其后面没有一致性或逻辑。 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. 作为参考,我的波特仅为1200,两个设备的电压绝对为3.3v,并且我确定Pi可以正常工作,因为当我将RX和TX短路时,我可以毫无问题地得到字节。 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. 我之所以选择UART是因为SPI给我带来了类似的问题,除了I2C之外,我想不出任何其他协议来解决问题。 I am using an external 32768hz crystal. 我正在使用外部32768hz晶体。 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: 在Pi上以1200运行minicom的输出,一次发送“ T”:

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

assuming Pi is working currectly... 假设Pi正在正常工作...

1.verify msp430 TX is woring: send every 1 sec known value and see if PI getting it currectly. 1.验证msp430 TX是否令人担忧:每隔1秒发送一次已知值,然后查看PI是否正确获取它。

2.verify MSP430 RX working: send from Pi known value every 1 sec. 2.验证MSP430 RX是否正常工作:每1秒从Pi发送一个已知值。

3.interrupt section: 3.中断部分:

  • your code dosent verfiy that RX interrupt is off. 您的代码确定RX中断已关闭。
  • you should filter interrupts generated only for the RX . 您应该过滤仅为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.. 为TX和RX(以及在中断和主循环部分)共享“输入”变量-不是一个好主意。

4.your output example suggests that you have baud rate mismatch issue. 4.您的输出示例表明您遇到波特率不匹配的问题。 if you send character 'T' and shoud get back 'T'. 如果您发送字符“ T”并应返回“ T”。 i expect to see 'TTTTTT...' BTW this garbage may suggests that you forgot to connecting GND line between two MCUs... 我希望看到'TTTTTT ...'顺便说一句,这个垃圾可能表明您忘记了在两个MCU之间连接GND线...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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