📄 lab-07-4619.c
字号:
//******************************************************************************
// MSP430xG46x Demo - USCI_B0, SPI Interface to MSP430F2013
//
// Description: This program demonstrate USCI_B0 in SPI mode interfaced to a
// MSP430F2013. The 'FG4619 transmits the SPI data via RS232 to a PC.
// ACLK = 32.768kHz, MCLK = SMCLK = default DCO ~1048k
//
// Slave Master
// MSP430F20x3 MSP430FG4619
// ----------------- -----------------
// | XIN|- /|\| XIN|-
// | | | | |
// | XOUT|- --|RST XOUT|-
// | | /|\ | |
// | RST/NMI|--+ | |
// | | | P2.5/UCA0RXD|------------>
// | | | | 115200 - 8N1
// | | | P2.4/UCA0TXD|<------------
// | | | |
// | SDI/P1.7|<-------|P3.1/UCB0SIMO |
// | SDO/P1.6|------->|P3.2/UCB0SOMI |
// | SCLK/P1.5|<-------|P3.3/UCBoCLK |
//
// FengLF
// LSD SCIENCE& TECHNOLOGY CO.,LTD
// 2007.06
// Built with IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include "msp430xG46x.h"
unsigned char ByteCount;
void Dealy()
{
unsigned int i;
unsigned int j;
for(i = 0; i< 5000; i++);
{
for(j = 0; j< 20000; j++);
}
}
void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW+WDTHOLD;
FLL_CTL0 |= XCAP14PF;
do
{
IFG1 &= ~OFIFG; // 清晶振失效标志位
for (i = 0x47FF; i > 0; i--);
}
while ((IFG1 & OFIFG)); // 晶振失效标志位仍置1?
P1IES|=0x01;
P1IE|=0x01;
//--- Initialization of RS232 Commuinication (USCI_A) --------------------------
P2SEL |= 0x030; // P2.4,5分别作为 USCI_A0的 RXD 和 TXD
UCA0CTL1 |= UCSSEL_2; // USCA0 时钟源 SMCLK
UCA0BR0 = 0x09; // 设置波特率 1048576/115200
UCA0BR1 = 0x00;
UCA0MCTL = 0x02; // 调制
UCA0CTL1 &= ~UCSWRST;
//IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
//--- Initialization of SPI Commuinication (USCI_B) ----------------------------
P3SEL |= 0x0C; // P3.3,2 功能选择
UCB0CTL0 |= UCMST+UCSYNC+UCMSB; // SPI 主机 3线制 高位先发
UCB0CTL1 |= UCSSEL_2; // USCB0 时钟源
UCB0BR0 = 0x20;
UCB0BR1 = 0;
UCB0CTL1 &= ~UCSWRST;
//--- Main Loop ----------------------------------------------------------------
while(1)
{
_BIS_SR(LPM3_bits + GIE); // 进入低功耗 LPM3
}
}
#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR (void)
{
P1IE &= ~0x01;
ByteCount=0;
UCA0TXBUF = 'S'; // 经串口发送数据 “SPI”
while(!(IFG2&UCA0TXIFG));
UCA0TXBUF = 'P';
while(!(IFG2&UCA0TXIFG));
UCA0TXBUF = 'I';
while(!(IFG2&UCA0TXIFG));
UCA0TXBUF = ':';
while(!(IFG2&UCA0TXIFG));
UCA0TXBUF = '"';
while(!(IFG2&UCA0TXIFG));
while(ByteCount<=21) // 通过SPI模式接收F2013发过来的21个数据
{ UCB0TXBUF = 0x00; // D空写启动SPI
while (!(IFG2 & UCB0RXIFG)); // USCI_B0 准备发送
ByteCount=ByteCount+1;
UCA0TXBUF = UCB0RXBUF; // 经串口发送数据到PC机
while(!(IFG2&UCA0TXIFG)); // 等待 TXbuffer为空 ?
}
UCA0TXBUF = '"'; // 经串口发送数据发送 “" ”
while(!(IFG2&UCA0TXIFG));
UCA0TXBUF = 10; // 发送回车键
while(!(IFG2&UCA0TXIFG));
UCA0TXBUF = 13;
while(!(IFG2&UCA0TXIFG));
P1IFG=0x00; // 清中断标志
LPM3_EXIT;
P1IE |= 0x01;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -