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.
各位大大好
我是MSP430的新手
最近在研究RS232 UART 的使用方法
可是我在電腦給數據後 他都不會進入中斷
我設斷點在中斷裡面 都沒有跑進中斷過 斷點也都沒有啟動
下面是我使用的程式
可以幫我看看有甚麼問題嗎?
是缺少了甚麼東西嗎?
/******************************************************************************
* 文件: main.c
* 說明: MSP430F5438的UART設置實驗
* 打開串口調試助手發送據據
* 觀察串口調試助手中接收數據區,數據的變化
* 編譯: IAR Embedded Workbench IDE for MSP430 v5.10
******************************************************************************/
#include "msp430x54x.h"
/*****************************************************************************
* 函數聲明區
*****************************************************************************/
void Init_RS232(void);
/******************************************************************************
* 變量定義區
******************************************************************************/
unsigned RX_buffer=0;
/*********************************系統主函數據********************************/
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // 關狗
P5DIR |=BIT4;
P5OUT |=BIT4;
Init_RS232(); //串口初始化
_EINT(); //開全局中斷
LPM1; //進入低功耗模式
}
/******************************************************************************
* 函數名:void Init_RS232(void)
* 功 能:RS232初始化
* 參 數:無
* 返回值:無
******************************************************************************/
void Init_RS232(void)
{
P3SEL = 0x30; // 選擇RS232引腳功能
P3DIR =BIT4;
P3DIR &=~BIT5;
UCA0CTL1 |= UCSWRST; // 復位UART狀態機
UCA0CTL1 |= UCSSEL_1; // CLK = ACLK
UCA0BR0 = 0x03; // 32kHz/9600=3.41
UCA0BR1 = 0x00; //
UCA0MCTL = UCBRS_3+UCBRF_0; // UCBRSx=3, UCBRFx=0
UCA0CTL1 &= ~UCSWRST; // 啟動UART
UCA0IE |= UCRXIE; // 數據接收中斷使能
}
/******************************************************************************
* 函數名:__interrupt void USCI_A3_ISR(void)
* 功 能:UART中斷函數
* 讀出 PC 機傳輸過來的數據並向PC機發送數據
* 參 數:無
* 返回值:無
******************************************************************************/
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
switch(__even_in_range(UCA0IV,4))
{
case 0:break; //
case 2: //
RX_buffer=UCA0RXBUF; //
while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX 緩衝區是否空閒
UCA0TXBUF = RX_buffer; // 串口發送數據,PC 機接收數據
_NOP(); // 設置斷點,觀察接收到的數據 RX_buffer
break;
case 4:break; //
default: break;
}
}
请参考附件官方例程
/* --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--*/ //****************************************************************************** // MSP430F543xA 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 // // MSP430F5438A // ----------------- // /|\| | // | | | // --|RST | // | | // | P3.4/UCA0TXD|------------> // | | 115200 - 8N1 // | P3.5/UCA0RXD|<------------ // // M. Morales // Texas Instruments Inc. // June 2009 // Built with CCE Version: 3.2.2 and IAR Embedded Workbench Version: 4.11B //****************************************************************************** #include <msp430.h> int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD UCA0CTL1 |= UCSWRST; // **Put state machine in reset** UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 = 9; // 1MHz 115200 (see User's Guide) UCA0BR1 = 0; // 1MHz 115200 UCA0MCTL |= UCBRS_1 + UCBRF_0; // Modulation UCBRSx=1, UCBRFx=0 UCA0CTL1 &= ~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 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=USCI_A0_VECTOR __interrupt void USCI_A0_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void) #else #error Compiler not supported! #endif { switch(__even_in_range(UCA0IV,4)) { case 0:break; // Vector 0 - no interrupt case 2: // Vector 2 - RXIFG while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = UCA0RXBUF; // TX -> RXed character break; case 4:break; // Vector 4 - TXIFG default: break; } }