MSP430F249UART
2013-04-12 10:33
120 查看
//******************************************************************************
// MSP430x24x Demo - USCI_A0, 9600 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 1MHz = 1MHz/9600 = ~104.2
// ACLK = n/a, MCLK = SMCLK = CALxxx_1MHZ = 1MHz
//
// MSP430F249
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P3.4/UCA0TXD|------------>
// | | 9600 - 8N1
// | P3.5/UCA0RXD|<------------
//
// B. Nisarga
// Texas Instruments Inc.
// September 2007
// Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
if (CALBC1_1MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600; (104)decimal = 0x068h
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
//__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
__bis_SR_register(GIE);
while(1)
{
int i;
for(i=10000;i>0;i--);
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = 'A'; // TX -> RXed character
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = 'B'; // TX -> RXed character
}
}
// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
}
// MSP430x24x Demo - USCI_A0, 9600 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 1MHz = 1MHz/9600 = ~104.2
// ACLK = n/a, MCLK = SMCLK = CALxxx_1MHZ = 1MHz
//
// MSP430F249
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P3.4/UCA0TXD|------------>
// | | 9600 - 8N1
// | P3.5/UCA0RXD|<------------
//
// B. Nisarga
// Texas Instruments Inc.
// September 2007
// Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
if (CALBC1_1MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600; (104)decimal = 0x068h
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
//__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
__bis_SR_register(GIE);
while(1)
{
int i;
for(i=10000;i>0;i--);
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = 'A'; // TX -> RXed character
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = 'B'; // TX -> RXed character
}
}
// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
}
相关文章推荐
- MSP430F249 IIC write and Uart send
- PL2303-UART转USB桥接器
- 知识点滴:什么是UART ?
- 基于微控制器的软件UART设计
- (原创)uart传输发送模块联合在一起进行测试
- ARM9硬件接口学习之 UART
- 《嵌入式linux应用程序开发完全手册》通用异步收发器UART学习笔记
- Uart串口实验--TQ2440
- I2C-SPI-UART
- at91sam7x256之gpio与串口 uart0
- SPI、I2C、UART三种串行总线的区别
- 示波器 && USBee Suite抓I2C && USBee 示波器 && USBee Suite抓上电时序 && USBee Suite抓取UART && 数据记录仪
- [转]linux设备模型之uart驱动架构分析(开始做驱动!!)
- UART 2440
- I2C,SPI,UART和CAN的区别(转载)
- 自己动手写的UART2驱动
- UART初始化时可以使用的参数
- 使用单片机的UART(COM口)进行传输 (单片机 LM3S811)
- 如何通过 tty_struct 得到 uart_port 结构体
- Linux终端设备驱动 ----UART的驱动