?? fet440_uart02_115200.c
字號:
//******************************************************************************
// MSP-FET430P440 Demo - USART0, 19200 UART Ultra-low Pwr Echo ISR, 32kHz ACLK
//
// Description: Echo a received character, USART0 RX ISR at high-speed used
// with ultra-low power techniques. Normal operation is LPM3. Use start-bit
// edge detect - URXSE - to automatically (re)enable DCO and trigger ISR. ISR
// must make sure DCO clock source remains enabled for the UART to receive
// full character.
// Software needs to make sure a character has been completely TX'ed, or RX'ed
// before entering LPM3, which disables DCO required for the USART baud rate
// generator. In the example, TX'ing is checked using the TXEPT bit directly.
// RX'ing is checked using the SSEL0 clock select bit as a flag. This is
// possible because UCLK0 = SMCLK when either both SSEL1 and SSEL0 or just
// SSEL1 = 1. In the example, when SSEL1 = SSEL0 = 1, there is no RX'ing, and
// LPM3 is allowed. When SSEL 1 = 1 and SSEL0 = 0, SMCLK is selected, but
// RX'ing is active and the DCO is required, thus LPM3 is not allowed.
// Baud rate divider with 1048576hz = 1048576Hz/115200 = ~9.1 (009h|08h)
// ACLK = LFXT1 = 32768Hz, MCLK = SMCLK = default DCO = 32 x ACLK = 1048576Hz
// //* An external watch crystal between XIN & XOUT is required for ACLK *//
//
// MSP430F449
// -----------------
// /|\| XIN|-
// | | | 32kHz
// --|RST XOUT|-
// | |
// | P2.4|----------->
// | | 19200 - 8N1
// | P2.5|<-----------
//
// M. Buccini
// Texas Instruments Inc.
// Feb 2005
// Built with IAR Embedded Workbench Version: 3.21A
//*****************************************************************************
#include <msp430x44x.h>
void uart_config(void); //UART初始化設置函數
#define Num_of_Results 8 //定義用于存放全局變量的數組
static unsigned int Rev_results[Num_of_Results];
void uart_config(void){
unsigned i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
FLL_CTL0 |= XCAP18PF; // Configure load caps
for (i = 0xFFFF; i > 0; i--); // Delay for FLL to set
P2SEL |= 0x30; // P2.4,5 引腳為串口通信腳
P2DIR |= 0xd0; // P2.4,P2.6,P2.7設置為輸出模式
//P2OUT &= ~0x80; // 芯片供電撤消,供電結束
P2OUT |= 0x80; // 芯片供電
P2OUT &= ~0x40; // 允許接收
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
UCTL0 |= CHAR; // 8-bit character, SWRST = 1
UTCTL0 |= SSEL1 + SSEL0 + URXSE; // UCLK = SMCLK, start edge detect
UBR00 = 0x09; // 調制波特率115200
UBR10 = 0x00;
UMCTL0 = 0x08;
UCTL0 &= ~SWRST; // Initialize USART state machine
IE1 |= URXIE0; // 允許中斷
}
void main(void)
{
uart_config();
_BIS_SR(LPM3_bits + GIE); // Enter LPM0 w/ interrupt
}
#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx (void)
{
if ((IFG1 & URXIFG0)) // Test URXIFG0
{
static unsigned int index = 0;
Rev_results[index] = RXBUF0; // RXBUF0 to TXBUF0
index = (index+1)%Num_of_Results; // Increment results index, modulo
_NOP(); // SET BREAKPOINT HERE
}
else // Start edge
{
UTCTL0 &= ~URXSE; // Clear URXS signal
UTCTL0 |= URXSE; // Re-enable edge detect
_BIC_SR_IRQ(SCG1 + SCG0); // DCO reamins on after reti
UTCTL0 &= ~SSEL0; // SSEL0= 0, RX activity
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -