Jump to content
43oh

MSP430G2553 and ADXRS450


Recommended Posts

Hello,

I try to comunicate with ADXRS450 via SPI. But receive data is always is same. All detail and code:

#include "msp430.h"
#include <signal.h>

#define CS_DIS {P1DIR|=BIT3;P1OUT|=BIT3;}
#define CS_ENA {P1DIR|=BIT3;P1OUT&=~BIT3;}

void SPI_Write(unsigned char Data_for_write);
void SPI_Disable(void);
void SPI_Init(void);
int SPI_Read(void);
void ADXRS450_Init(void);

unsigned char Byte;

long Measure_byte_first;
long Measure_byte_second;
long Measure_byte_third;
long Measure_byte_four;
long Measurement;

int main()
{
  WDTCTL = WDTPW + WDTHOLD;

  CS_DIS;

  SPI_Init();
  __delay_cycles(10000);
  ADXRS450_Init();
  while((UCB0STAT&UCBUSY));

for(;
{
      CS_ENA;
      while((UCB0STAT&UCBUSY));
      SPI_Write(0x20);
      SPI_Write(0x00);
      SPI_Write(0x00);
      SPI_Write(0x00);
      while((UCB0STAT&UCBUSY));
      CS_DIS;

      __delay_cycles(50000);

      CS_ENA;
      while((UCB0STAT&UCBUSY));
      SPI_Write(0x00);
      Measure_byte_first = UCA0RXBUF;
      SPI_Write(0x00);
      Measure_byte_second = (UCA0RXBUF<<8);
      SPI_Write(0x00);
      Measure_byte_third = (UCA0RXBUF<<8);
      SPI_Write(0x00);
      Measure_byte_four = (UCA0RXBUF<<8);
      while((UCB0STAT&UCBUSY));
      CS_DIS;

      Measurement = (Measure_byte_first | Measure_byte_second | Measure_byte_third | Measure_byte_four);
      Measurement = (int)((Measurement & 0x3FFFC00) >> 10);
      Measurement = ((Measurement) / 80);
      __delay_cycles(50000);
}
}

void SPI_Init(void)
{
    P1SEL = BIT1 + BIT2 + BIT4;
    P1SEL2 = BIT1 + BIT2 + BIT4;

    UCA0CTL1 = UCSWRST;
    UCA0CTL0 |= UCMSB + UCMST + UCSYNC + UCCKPL;                      // 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**
}

void SPI_Write(unsigned char Byte)
{
    while (!(IFG2 & UCA0TXIFG));

    UCA0TXBUF = Byte;
}

void SPI_Disable(void)
{
    UCB0CTL1 |= UCSWRST;
}

int SPI_Read(void)
{
    while (!(IFG2 & UCA0RXIFG));

    UCA0TXBUF = 0x00;

    return UCA0RXBUF;
}

void ADXRS450_Init(void)
{
    __delay_cycles(150000);
    CS_ENA;
    SPI_Write(0x20);
    SPI_Write(0x00);
    SPI_Write(0x00);
    SPI_Write(0x03);
    CS_DIS;
    __delay_cycles(150000);
    CS_ENA;
    SPI_Write(0x20);
    SPI_Write(0x00);
    SPI_Write(0x00);
    SPI_Write(0x00);
    CS_DIS;
    __delay_cycles(250000);
    CS_ENA;
    SPI_Write(0x20);
    SPI_Write(0x00);
    SPI_Write(0x00);
    SPI_Write(0x00);
    CS_DIS;
    __delay_cycles(250000);
    CS_ENA;
    SPI_Write(0x20);
    SPI_Write(0x00);
    SPI_Write(0x00);
    SPI_Write(0x00);
    CS_DIS;
    __delay_cycles(250000);
}

post-31760-0-90893800-1379326307_thumb.jpg

Link to post
Share on other sites
  • 4 months later...

This looks incorrect:

      SPI_Write(0x00);
      Measure_byte_first = UCA0RXBUF;
      SPI_Write(0x00);
      Measure_byte_second = (UCA0RXBUF<<8);
      SPI_Write(0x00);
      Measure_byte_third = (UCA0RXBUF<<8);
      SPI_Write(0x00);
      Measure_byte_four = (UCA0RXBUF<<8);
      while((UCB0STAT&UCBUSY));
      CS_DIS;

      Measurement = (Measure_byte_first | Measure_byte_second | Measure_byte_third | Measure_byte_four);
      Measurement = (int)((Measurement & 0x3FFFC00) >> 10);
      Measurement = ((Measurement) / 80);

How about this?

      SPI_Write(0x00);
      Measure_byte_first = UCA0RXBUF;
      SPI_Write(0x00);
      Measure_byte_second = UCA0RXBUF;
      SPI_Write(0x00);
      Measure_byte_third = UCA0RXBUF;
      SPI_Write(0x00);
      Measure_byte_four = UCA0RXBUF;
      while((UCB0STAT&UCBUSY));
      CS_DIS;

      Measurement = (Measure_byte_first | (Measure_byte_second<<8) | (Measure_byte_third<<16) | (Measure_byte_four<<24));
      Measurement = (int)((Measurement & 0x3FFFC00) >> 10);
      Measurement = ((Measurement) / 80);
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...