采用的教材上的例程,SPI的自收自发没问题,但是将两片430f6638的spi接口连接起来时,作为接收端的从机总是出现溢出的错误,接收到的数据也很乱,不知道怎么回事,同时主机的UCTXIFG总是为1,当将数据写入UCA1TXBUF时仍然为1,好多问题,希望论坛里的高手给予帮助,谢谢了!
下面是我的从机接收端的程序,程序不长,还麻烦大家帮帮忙
#include <msp430f6638.h>
unsigned int MST_Data,SLV_Data;
unsigned char temp;
void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
P8SEL = BIT1+BIT2+BIT3; //USCI_A1的8.2为SIMO,8.3为SOMI,8.1为USCI_A1的CLK
P8DIR = BIT3; //SOMI端口设为输出
P8DIR &= ~BIT2; // SIMO端口设为输入
P8DIR &= ~BIT1; //CLK设为输入
P1REN |= BIT4; // Enable P1.4 internal resistance
P1OUT |= BIT4; // Set P1.4 as pull-Up resistance
P1IES &= ~BIT4; // P1.4 Lo/Hi edge
P1IFG &= ~BIT4; // P1.4 IFG cleared
P1IE |= BIT4; // P1.4 interrupt enabled
UCA1CTL1|=UCSWRST;
UCA1CTL0|= UCSYNC+UCCKPL+UCMSB;
UCA1CTL1&=~UCSWRST;
__bis_SR_register(LPM0_bits+GIE);
}
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
switch(__even_in_range(UCA1IV,4))
{
case 0: break;
case 2:
while (!(UCA1IFG&UCTXIFG))
UCA1TXBUF = UCA1RXBUF;
__delay_cycles(500);
break;
case 4: break;
default: break;
}
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1IFG &= ~BIT4; // Clear P1.4 IFG
P1IE &= ~ BIT4; // Clear P1.4 IE
UCA1CTL1 |= UCSWRST; // Master is ready
UCA1CTL1 &= ~UCSWRST; // Re-init slave state machine
UCA1IE |= UCRXIE; // Enable RX interrupt
}
此帖出自
小平头技术问答
这是之前作为主机发送时的程序修改了,忘了注释了,应该删了
一周热门 更多>