本帖最后由 Suncow0319 于 2012-9-1 09:53 编辑
两个MSP430F149进行SPI通信,主机发送数据正常,为什么从机接收不到?(从机的U0RXBUF一直为0)
通过示波器可以看到主机的SIMO输出的结果是正确的。
附程序:
主机程序:
#include <msp430x14x.h>
char MST_Data = 0x00;
void main(void)
{
unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL = 0x00E; // Setup P3 for SPI mode
P3OUT = 0x020; // Setup P3.4 for Scope trigger and
P3DIR |= 0x030; // P3.5 for slave initialization
U0CTL = CHAR + SYNC + MM + SWRST; // 8-bit, SPI, Master
U0TCTL = CKPL + SSEL1 + STC; // Polarity, SMCLK, 3-wire
U0BR0 = 0x002; // SPICLK = SMCLK/2
U0BR1 = 0x000;
U0MCTL = 0x000;
ME1 = USPIE0; // Module enable
U0CTL &= ~SWRST; // SPI enable
IE1 |= URXIE0; // Recieve interrupt enable
_EINT(); // Enable interrupts
P3OUT &= ~0x020; // Toggle P3.5: slave reset
P3OUT |= 0x020;
i = 50000; // Delay
do (i--);
while (i != 0);
while (1)
{
TXBUF0 = MST_Data; // Transmit first character
LPM0; // CPU off
}
} // End Main
#pragma vector=USART0RX_VECTOR
__interrupt void SPI0_rx (void)
{
P3OUT ^= 0x010; // XOR P3.4 for scope trigger
while ((IFG1 & UTXIFG0) == 0); // USART0 TX buffer ready?
TXBUF0 = 0x0F;
}
从机程序:
#include <msp430x14x.h>
char MST_Data = 0x00, SLV_Data = 0xFF;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= 0x0E; // Setup P3 for SPI mode
U0CTL &=~MM;
U0CTL = CHAR + SYNC + SWRST; // 8-bit, SPI, Slave
U0TCTL = CKPL + STC; // Polarity, UCLK, 3-wire
ME1 = USPIE0; // Module enable
U0CTL &= ~SWRST; // SPI enable
while (1)
{
if(IFG1 & URXIFG0)
{
while (!(IFG1 & UTXIFG0));
TXBUF0 = U0RXBUF;
LPM4;
}
}
}
刚开始测试的时候发现不能进入中断服务函数,所以我直接改成了现在查询方式输出,这样可以吗?
谢谢各位高手指教啦! |