TI中文支持网
TI专业的中文技术问题搜集分享网站

MSP430F5529: 使用例程与pc端上位机无法进行数据传输

Part Number:MSP430F5529Other Parts Discussed in Thread:MSP-EXP430F5529LP

#include <msp430f5529.h>

void main(void)
{WDTCTL = WDTPW + WDTHOLD;// Stop WDTP3SEL |= BIT3+BIT4;// P3.3,4 = USCI_A0 TXD/RXDUCA0CTL1 |= UCSWRST;// **Put state machine in reset**UCA0CTL1 |= UCSSEL_2;// SMCLKUCA0BR0 = 9;// 1MHz 115200 (see User's Guide)UCA0BR1 = 0;// 1MHz 115200UCA0MCTL |= UCBRS_1 + UCBRF_0;// Modulation UCBRSx=1, UCBRFx=0UCA0CTL1 &= ~UCSWRST;// **Initialize USCI state machine**UCA0IE |= UCRXIE;// Enable USCI_A0 RX interrupt__bis_SR_register(LPM0_bits + GIE);// Enter LPM0, interrupts enabled__no_operation();// For debugger
}

// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{switch(__even_in_range(UCA0IV,4)){case 0:break;// Vector 0 - no interruptcase 2:// Vector 2 - RXIFGwhile (!(UCA0IFG&UCTXIFG));// USCI_A0 TX buffer ready?UCA0TXBUF = UCA0RXBUF;// TX -> RXed characterbreak;case 4:break;// Vector 4 - TXIFGdefault: break;}
}

Susan Yang:

您使用的是launchpad?那您需要修改部分代码

USCI_A0 改为使用 USCI_A1

P3SEL 需要改为 P4SEL |= BIT4+BIT5;

整体代码如下

/* --COPYRIGHT--,BSD_EX* Copyright (c) 2012, Texas Instruments Incorporated* All rights reserved.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions* are met:** *Redistributions of source code must retain the above copyright*notice, this list of conditions and the following disclaimer.** *Redistributions in binary form must reproduce the above copyright*notice, this list of conditions and the following disclaimer in the*documentation and/or other materials provided with the distribution.** *Neither the name of Texas Instruments Incorporated nor the names of*its contributors may be used to endorse or promote products derived*from this software without specific prior written permission.** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.**********************************************************************************MSP430 CODE EXAMPLE DISCLAIMER** MSP430 code examples are self-contained low-level programs that typically* demonstrate a single peripheral function or device feature in a highly* concise manner. For this the code may rely on the device's power-on default* register values and settings such as the clock configuration and care must* be taken when combining code from several examples to avoid potential side* effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware* for an API functional library-approach to peripheral configuration.** --/COPYRIGHT--*/
//******************************************************************************
//MSP430F552x Demo - USCI_A0, 115200 UART Echo ISR, DCO SMCLK
//
//Description: Echo a received character, RX ISR used. Normal mode is LPM0.
//USCI_A0 RX interrupt triggers TX Echo.
//Baud rate divider with 1048576hz = 1048576/115200 = ~9.1 (009h|01h)
//ACLK = REFO = ~32768Hz, MCLK = SMCLK = default DCO = 32 x ACLK = 1048576Hz
//See User Guide for baud rate divider table
//
//MSP430F552x
//-----------------
///|\||
//| ||
//--|RST|
//||
//|P3.3/UCA0TXD|------------>
//|| 115200 - 8N1
//|P3.4/UCA0RXD|<------------
//
//Bhargavi Nisarga
//Texas Instruments Inc.
//April 2009
//Built with CCSv4 and IAR Embedded Workbench Version: 4.21
//******************************************************************************#include <msp430.h>int main(void)
{WDTCTL = WDTPW + WDTHOLD;// Stop WDTP4SEL |= BIT4+BIT5;// P3.3,4 = USCI_A0 TXD/RXDUCA1CTL1 |= UCSWRST;// **Put state machine in reset**UCA1CTL1 |= UCSSEL_2;// SMCLKUCA1BR0 = 9;// 1MHz 115200 (see User's Guide)UCA1BR1 = 0;// 1MHz 115200UCA1MCTL |= UCBRS_1 + UCBRF_0;// Modulation UCBRSx=1, UCBRFx=0UCA1CTL1 &= ~UCSWRST;// **Initialize USCI state machine**UCA1IE |= UCRXIE;// Enable USCI_A0 RX interrupt__bis_SR_register(LPM0_bits + GIE);// Enter LPM0, interrupts enabled__no_operation();// For debugger
}// Echo back RXed character, confirm TX buffer is ready first
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void)
#else
#error Compiler not supported!
#endif
{switch(__even_in_range(UCA1IV,4)){case 0:break;// Vector 0 - no interruptcase 2:// Vector 2 - RXIFGwhile (!(UCA1IFG&UCTXIFG));// USCI_A0 TX buffer ready?UCA1TXBUF = UCA1RXBUF;// TX -> RXed characterbreak;case 4:break;// Vector 4 - TXIFGdefault: break;}
}

,

Zhengyuan Fang Fang:

你好,我试了一下,还是没法在上位机上显示数据

,

Susan Yang:

上面的程序是我刚刚测试过的

使用的是MSP-EXP430F5529LP

例程是回显,您需要在串口助手输入一个字符,如 1

而后点击CCS内的运行按键,暂停后,串口助手就会出现 1

,

Zhengyuan Fang Fang:

谢谢,解决了,一直没结果原因是跳线帽没有接好

,

Susan Yang:

很高兴您能解决问题

,

Zhengyuan Fang Fang:

你知道怎么样用printf来在端口打印数字吗

,

Susan Yang:

已经在下面的链接回复

https://e2echina.ti.com/support/microcontrollers/msp430/f/msp-low-power-microcontroller-forum/205448/msp430f5529-printf 

赞(0)
未经允许不得转载:TI中文支持网 » MSP430F5529: 使用例程与pc端上位机无法进行数据传输
分享到: 更多 (0)

© 2024 TI中文支持网   网站地图 鲁ICP备2022002796号-1