已回答假定已回答

MSP430F149通过SPI读取ADXL362

NJUST-ST 在 2015-11-3 詢問的問題
最後回覆由adi_susan於2015-11-13提供

现在的问题是当我要去读ADXL362时,先片选,但是一片选,430的SIMO口的电压就被拉高,但是它能在SMCLK时钟下发送正确的信号。程序如下,新生请谅解。我还附件了时钟与主机输出信号图,还有一张是片选和主机输出信号图。

#include <msp430f149.h>

#define CPU_F ((double)8000000)

#define delay_us(x)__delay_cycles((long)(CPU_F*(double)x/1000000.0))

#define delay_ms(x)__delay_cycles((long)(CPU_F*(double)x/1000.0))

 

 

void Init_CLK(void)

{

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  unsigned int i;

  BCSCTL1 &=~XT2OFF;

  do

  {

  IFG1 &=~OFIFG;

  for(i=0xFF;i>0;i--);

  }

  while((IFG1 & OFIFG));

  BCSCTL2 |=0x8B;

}

void UCB0_SPI(void)   //UCB0 SPI配置

{

   P5SEL |=0x0E;      //选择口5.1,5.2,5.3

   U1CTL |= SWRST;

   U1CTL |= CHAR + SYNC + MM + SWRST;         // 8-bit, SPI, Master

   U1TCTL |= CKPH + SSEL1 + STC;              // Polarity, SMCLK, 3-wire

   U1BR0 = 0x02;                             // SPICLK = SMCLK/2

   U1BR1 = 0x00;

   U1MCTL = 0x00;

   ME2 |= USPIE1;                            // Enable USART1 SPI mode

   U1CTL &= ~SWRST;

}

unsigned char ADXL_SPI_read()

{

  unsigned char k;

  P2DIR |=0x08;

  P2OUT &=~0x08;

  TXBUF1=0x0B;

  while (!(IFG2 & UTXIFG1));

  TXBUF1=0x00;

  while (!(IFG2 & UTXIFG1));

  TXBUF1=0xFF;

  while (!(IFG2 & UTXIFG1));

  k=RXBUF1;

  P2OUT|=0x08;

  return k;

}

void main(void)

{

  P5SEL |=BIT5;

  P5DIR |=BIT5;

  Init_CLK();

  UCB0_SPI();

  while(1)

  {

  P2DIR |=0X10;

  P2OUT ^=0X10;

  ADXL_SPI_read();

    delay_ms(5);

附件

結果