This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

initializing ads1240 via spi with msp430g2553

Other Parts Discussed in Thread: ADS1240, MSP430G2553

Hello!

Can you help me with starting up my ads1240.

I have connected ads1240 and msp430g2553. but the problem that i have had zero response from ads,when i'm sending command RDATA. UCA0RXBUF=0x00.may be in the beginning i didn't finished all procedures to initialize ads device. I have sent commands RESET and SELFCAL through spi. Are there any errors in the code?

And there is one more problem,in response only one byte,i didn't have other two bytes

#include "msp430g2553.h"

void set_dco(void);
void init_spi(void);

#define RST 0xFE
#define SELFCAL 0xF0
#define RDATA 0x01

void main(void)
{

char c='0';

WDTCTL = WDTPW | WDTHOLD;

set_dco();
 init_spi();


P1OUT &= ~BIT4; //CS low
while (!(IFG2&UCB0TXIFG));
UCB0TXBUF=RST;
__delay_cycles(1000);
while (!(IFG2&UCB0TXIFG));
UCB0TXBUF=SELFCAL;
__delay_cycles(1000);
P1OUT |= BIT4;

while(1)
{

P1OUT &= ~BIT4; //CS low

while (!(IFG2&UCB0TXIFG));
UCB0TXBUF=RDATA;

__delay_cycles(1000);

while (!(IFG2&UCB0RXIFG));
c=UCB0RXBUF;

P1OUT |= BIT4;


}
}


void set_dco()
{
BCSCTL1 = 0x86; // Set DCO 1 MHz
DCOCTL = 0xD1;
}

void init_spi()

{
P1SEL |= BIT6 + BIT7 + BIT5; //SPI pin
P1SEL2 |= BIT6 + BIT7 + BIT5;


P1DIR |= BIT4; // cs select


UCB0CTL0 |=  UCMSB + UCMST + UCSYNC; //3 pin master mode sync
UCB0CTL1 |= UCSSEL_2; // SMCLK
UCB0BR0 |= 0x02; // bit rate?? /2
UCB0BR1 = 0; //
UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCB0RXIE; // Enable USCI0 RX interrupt

P1OUT &= ~BIT4; // Now with SPI signals initialized,
P1OUT |= BIT4; // reset slave

__delay_cycles(75); //?? need delay to initialize slave
}

  • Sindi,

    The best troubleshooting tool you can use here is an oscilloscope.  I have not gone through all your code settings, but when reading out the device the SCLK is initiated with a write to the TX buffer.  This is a full-duplex operation, so when the TX buffer is written the RX buffer will also receive data.  You are only sending the TX buffer the RDATA command, and what you have read back is the response of the ADS1240 while sending the RDATA command.  You have not read out any data, which will require 3 more bytes of transfer.  This means you need to write a NOP command to the TX buffer three times.  After each TX buffer write you will need to capture and align the data from the RX buffer appropriately.  This includes sign extension.

    You've started out with the correct process, but you need to take it a little bit further.  An oscilloscope will help you in determing if your communication sequence is actually the way you think you've programmed the MSP430.

    Best regards,

    Bob B

  • Thank you for your answer.

    How can  I  describe NOP command? In this situation I haven't used RDATAC,this is not continuous mode

    I try this sequence of command,but I'm receiving wrong data,I have checked by writing and reading register from ads,it has differnet values.

    void read_ads()
    {


    P1OUT &= ~BIT4; //CS low

    transmit_spi(RDATA);
    __delay_cycles(ADS_DELAY);

    transmit_spi(RDATA+1);
    __delay_cycles(ADS_DELAY);
    value[0]=receive_spi();

    transmit_spi(RDATA+2);
    __delay_cycles(ADS_DELAY);
    value[1]=receive_spi();

    transmit_spi(RDATA+3);
    __delay_cycles(ADS_DELAY);
    value[2]=receive_spi();

    __delay_cycles(ADS_DELAY);

    P1OUT |= BIT4; //CS high


    }

  • I have transmitted every time '1' when waiting the 3 answer bytes.Is this ok? Do I need to delay every time after transmission through spi?

    void read_ads()
    {


    P1OUT &= ~BIT4; //CS low

    transmit_spi(RDATA);
    __delay_cycles(ADS_DELAY);

    transmit_spi('1');
    __delay_cycles(ADS_DELAY);
    value[0]=receive_spi();

    transmit_spi('1');
    __delay_cycles(ADS_DELAY);
    value[1]=receive_spi();

    transmit_spi('1');
    __delay_cycles(ADS_DELAY);
    value[2]=receive_spi();

    __delay_cycles(ADS_DELAY);

    P1OUT |= BIT4; //CS high


    }

  • Sindi,

    Can you send scope shots of the communication?  The SPI peripheral is full duplex, meaning data is sent and received with the same set of clocks. The clocks are initiated with a write to the TX buffer.  You should always clear the buffer following the TX to make sure you are using the correct data from the RX buffer.  Seeing scope shots will help in determining whether you have set up your system properly.

    Best regards,

    Bob B