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

msp430g2313 slave spi问题

目前使用msp430g2313来处理slave spi,遇到问题,使用TI提供的红色调试版,外接SPI信号,发现SPI CLOCK只要有信号就能进入中断,请求帮助,代码如下:

//                MSP430G2xx3
//             —————–
//         /|\|              XIN|-
//          | |                 |
//          | |             XOUT|-
// Master—+-|RST              |
//            |             P1.2|<- Data Out (UCA0SOMI)
//            |                 |
//            |             P1.1|-> Data In (UCA0SIMO)
//            |                 |
//            |             P1.4|<- Serial Clock In (UCA0CLK)
//
//   D. Dang
//   Texas Instruments Inc.
//   February 2011
//   Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************
#include <msp430.h>

unsigned char tmp = 0;
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 + BIT0;
  P1SEL2 = BIT1 + BIT2 + BIT4;
  P1DIR |= BIT0;
  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

 _EINT();
  //__bis_SR_register(LPM4_bits + GIE);       // Enter LPM4, enable interrupts
        while(1)
        {
                 }
}
// 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 = UCA0RXBUF;
  //tmp++;
    if(tmp==1)
    {
      P1OUT |= BIT0;
      tmp = 0;
    }
    else
    {
      tmp = 1;
      P1OUT &= ~BIT0;
    }
}

HG:

1. P1SEL = BIT1 + BIT2 + BIT4 + BIT0;  P1SEL2 = BIT1 + BIT2 + BIT4;  P1DIR |= BIT0;

  为啥把BIT0选成专用的了还要置成output 0?

2. 确认进的是UART的接收中断么?

所以,要验证三线的,先改成

P1SEL = BIT1 + BIT2 + BIT4 ;  P1SEL2 = BIT1 + BIT2 + BIT4;

并且把_EINT();先屏蔽掉试试呢

tao chen8:

回复 HG:

1. P1SEL = BIT1 + BIT2 + BIT4 + BIT0;  P1SEL2 = BIT1 + BIT2 + BIT4;  P1DIR |= BIT0;

  为啥把BIT0选成专用的了还要置成output 0?

—- P1.0 用来做LED用

2. 确认进的是UART的接收中断么?

 —- 断点调试是由进入#pragma vector=USCIAB0RX_VECTOR中断

所以,要验证三线的,先改成

P1SEL = BIT1 + BIT2 + BIT4 ;  P1SEL2 = BIT1 + BIT2 + BIT4;

并且把_EINT();先屏蔽掉试试呢

—- 最早是使用 __bis_SR_register(LPM4_bits + GIE);方式开中断,但是效果一样,P1.4(clk)不管接什么信号,都会进入中断

HG:

回复 HG:

用LED的话就不要选专用了,选DIR和OUTPUT就行了

tao chen8:

回复 kqian0327:

Michael,多谢,确实是时钟没有设置,另外你的客户不会就是我吧。。哈哈

赞(0)
未经允许不得转载:TI中文支持网 » msp430g2313 slave spi问题
分享到: 更多 (0)