TI中文支持网
TI专业的中文技术问题搜集分享网站

lunchpad MSP430G2553上使用SPI的问题?

lunchpad  MSP430G2553上使用SPI的官方例程如下:

//****************************************************************************** #include "msp430g2553.h"

void 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 #pragma vector=USCIAB0RX_VECTOR __interrupt void USCI0RX_ISR (void) {   while (!(IFG2 & UCA0TXIFG));              // USCI_A0 TX buffer ready?   UCA0TXBUF = UCA0RXBUF; }

我下载进去,调试的时候,程序一直死在 while (!(P1IN & BIT4));     这个语句上…请问这是什么原因??SPI也不能自发自收…

bryant peter:

上面程序没发清楚….我再重新发下:

#include "msp430g2553.h"

void 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 #pragma vector=USCIAB0RX_VECTOR __interrupt void USCI0RX_ISR (void)

{  

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

  UCA0TXBUF = UCA0RXBUF;

}

jin yuan:

回复 bryant peter:

 

#include "msp430g2553.h"

void 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

#pragma vector=USCIAB0RX_VECTOR

__interrupt void USCI0RX_ISR (void)

 {  

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

   UCA0TXBUF = UCA0RXBUF;

}

Ken Wang:

回复 jin yuan:

楼主,

 首先这是SPI的一个master程序,你搭建的平台,slave那一段少写了相应的程序吗?

另外关于SPi的接线,先确认mosi,miso,clk都有接正确,同时slave的cs拉低了。

谢谢

赞(0)
未经允许不得转载:TI中文支持网 » lunchpad MSP430G2553上使用SPI的问题?
分享到: 更多 (0)