📄 fg4619_s_spi.c
字号:
//******************************************************************************
// MSP430xG46x Demo - USART1, SPI 3-Wire Slave Data Echo
//
// Description: SPI slave talks to SPI master using 3-wire mode. Data received
// from master is echoed back. USART1 RX ISR is used to handle communication,
// CPU normally in LPM4. Prior to initial data exchange, master pulses
// slaves RST for complete reset.
// ACLK = 32.768kHz, MCLK = SMCLK = DCO = ~1048kHz
//
// Use with SPI Master Incremented Data code example. If the slave is in
// debug mode, the reset signal from the master will conflict with slave's
// JTAG; to work around, use IAR's "Release JTAG on Go" on slave device. If
// breakpoints are set in slave RX ISR, master must stopped also to avoid
// overrunning slave RXBUF.
//
// MSP430xG461x MSP430xG461x
// ----------------- -----------------
// /|\| XIN| | | /|\
// | | | | | |
// --|RST XOUT| | RST|------Master
// | | | |
// | P4.3|SIMO1<----->SOMI1|P4.3 |
// | | | |
// LED <-|P5.1 P4.4|SOMI1<----->SIMO1|P4.4 XIN |-
// | | | | 32KHZ
// Slave reset <-|P5.2 P4.5|UCLK1<----->UCLK1|P4.5 XOUT|-
//
//
// K. Quiring/ M. Mitchell
// Texas Instruments Inc.
// March 2006
// Built with IAR Embedded Workbench Version: 3.41A
//******************************************************************************
#include <msp430xG46x.h>
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)); //
for(i=2100;i>0;i--); //
while(!(P4IN&0x20)); //
P4SEL |= 0x038; // P4.5,4,3 选择 SPI 功能
U1CTL = CHAR+SYNC+SWRST; // 8-bit, SPI, 从机
U1TCTL |= CKPL+STC; // 极性, UCLK, 3线制
ME2 |= USPIE1; // 模块使能
U1CTL &= ~SWRST; // SPI 使能
IE2 |= URXIE1; // 接收中断使能
_BIS_SR(LPM4_bits + GIE); // 开中断,进入低功耗 LPM4
}
#pragma vector=USART1RX_VECTOR
__interrupt void USART1RX_ISR (void)
{
while (!(IFG2 & UTXIFG1)); // USART1 发送准备?
U1TXBUF = U1RXBUF;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -