初学SPI,调用了例程中的SPI 程序,发现中断中UCA0RXBUF的值一直都是0xff, 灯亮只发生在SLV_Data也等于0xff时,为什么???
求大神指点
附源程序:
//******************************************************************************
// MSP430G2xx3 Demo - USCI_A0, SPI 3-Wire Master Incremented Data
//
// Description: SPI master talks to SPI slave using 3-wire mode. Incrementing
// data is sent by the master starting at 0x01. Received data is expected to
// be same as the previous transmission. USCI RX ISR is used to handle
// communication with the CPU, normally in LPM0. If high, P1.0 indicates
// valid data reception.
// ACLK = n/a, MCLK = SMCLK = DCO ~1.2MHz, BRCLK = SMCLK/2
//
// Use with SPI Slave Data Echo code example. If slave is in debug mode, P3.6
// slave reset signal conflicts 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.
//
// MSP430G2xx3
// -----------------
// /|| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P1.2|-> Data Out (UCA0SIMO)
// | |
// LED <-|P1.0 P1.1|<- Data In (UCA0SOMI)
// | |
// Slave reset <-|P1.5 P1.4|-> Serial Clock Out (UCA0CLK)
//
//
// D. Dang
// Texas Instruments Inc.
// February 2011
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************
#include "msp430g2553.h"
unsigned char MST_Data, SLV_Data;
void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1OUT = 0x00; // P1 setup for LED & reset output
P1DIR |= BIT0 + BIT5; //
P1SEL = BIT1 + BIT2 + BIT4; //BIT1 :SPIMISO,BIT2 :SPIMOSI,BIT4:UCA0CLK
P1SEL2 = BIT1 + BIT2 + BIT4;
UCA0CTL0 |= UCCKPL + UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 |= 0x02; // /2
UCA0BR1 = 0; //
UCA0MCTL = 0; // No modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
P1OUT &= ~BIT5; // Now with SPI signals initialized,
P1OUT |= BIT5; // reset slave
__delay_cycles(75); // Wait for slave to initialize
MST_Data = 0x01; // Initialize data values
SLV_Data = 0x00;
UCA0TXBUF = MST_Data; // Transmit first character
__bis_SR_register(LPM0_bits + GIE); // CPU off, enable interrupts
}
// Test for valid RX and TX character
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCIA0RX_ISR(void)
{
volatile unsigned int i;
while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
if (UCA0RXBUF == SLV_Data) // Test for correct character RX'd
P1OUT |= BIT0; // If correct, light LED
else
P1OUT &= ~BIT0; // If incorrect, clear LED
MST_Data++; // Increment master value
SLV_Data++; // Increment expected slave value
UCA0TXBUF = MST_Data; // Send next value
__delay_cycles(50); // Add time between transmissions to
} // make sure slave can keep up
此帖出自
小平头技术问答
程序直接运行的时候能看到G2553的P1.0对应的红灯微弱的亮,感觉程序可能对了,然后就单步执行,发现中断中UCA0RXBUF的值一直都是0xff, 灯亮只发生在SLV_Data也等于0xff时,如果这样的话,貌似与原程序目的不一样啊
一周热门 更多>