Quantcast
Channel: MSP 低功耗微控制器论坛 - 最近的话题
Viewing all articles
Browse latest Browse all 3634

MSP430G2553 SPI SLAVE模式发送时没个数据发了两次?

$
0
0

参考倒程"msp430g2xx3_uscia0_spi_10.c"写了以下SPI通信程序,单片机作为从设备,主设备是以“字”的形式来读取信息。

设计应该是04 06 08 依次发出,但实际观察到单片机发送的是两个相同的字节。如:04 04 06 06或06 06 08 08。这是什么原因呢?

 

#include <msp430.h> 

 

 

/**

 * main.c

 */

 

int main(void)

{

  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer

 // while (!(P1IN & BIT4));                   // If clock sig from mstr stays low,

                                            // it is not yet in SPI mode

 

  P1SEL = BIT1 + BIT2 + BIT4;

  P1SEL2 = BIT1 + BIT2 + BIT4;

  UCA0CTL1 = UCSWRST;                       // **Put state machine in reset**

  UCA0CTL0 |= UCCKPL + UCMSB + UCSYNC;      // 3-pin, 8-bit SPI master

  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**

  IE2 |= UCA0RXIE;                          // Enable USCI0 RX interrupt

 

  __bis_SR_register(LPM4_bits + GIE);       // Enter LPM4, enable interrupts

}

 

// Echo character

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)

#pragma vector=USCIAB0RX_VECTOR

__interrupt void USCI0RX_ISR (void)

#elif defined(__GNUC__)

void __attribute__ ((interrupt(USCIAB0RX_VECTOR))) USCI0RX_ISR (void)

#else

#error Compiler not supported!

#endif

{

    while (!(IFG2 & UCA0TXIFG));              // USCI_A0 TX buffer ready?

    UCA0TXBUF = 0x04;

    while (!(IFG2 & UCA0TXIFG));              // USCI_A0 TX buffer ready?

    UCA0TXBUF = 0x06;

    while (!(IFG2 & UCA0TXIFG));              // USCI_A0 TX buffer ready?

    UCA0TXBUF = 0x08;

}

 


Viewing all articles
Browse latest Browse all 3634

Trending Articles