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.

msp430fr4133: ads1231 interface with msp430fr4133

Part Number: MSP430FR4133
Other Parts Discussed in Thread: ADS1231, , ADS1231REF, ENERGIA

Hello,

 I  want to interface ads1231 to msp430r4133 using SPI communication. I am writting code for this :-

#include "msp430fr4133.h"
#include "stdbool.h"
int SPI(void)
{
unsigned int data2, data3, signExtension;
long int data1;
int sign;
bool dataComplete = false;

P5SEL0 |= BIT1 |BIT3 ; // set 2-SPI pin as second function

P5DIR |= 0x01;


UCB0CTLW0 |= UCSWRST; // **Put state machine in reset**
UCB0CTLW0 |= UCMST|UCSYNC|UCCKPL|UCMSB; // 3-pin, 8-bit SPI master
// Clock polarity high, MSB
UCB0CTLW0 |= UCSSEL__SMCLK; // Select SMCLK
UCB0BR0 = 0x01; // /2,fBitClock = fBRCLK/(UCBRx+1).
UCB0BR1 = 0; //
// UCA0MCTLW = 0; // No modulation
UCB0CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
UCB0IE |= UCRXIE; // Enable USCI_A0 RX interrupt

PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
// to activate previously configured port settings


/* The msp430 should only go in this loop everytime DRDY is low. This means that it needs to get the 24 bits of data and then DRDY should be high again. It will stay high until
the ADS is ready to send more data out.*/
while(1)
{
if( dataComplete){ //the code should go into this for loop at the 25th SCLK and then stop the SCLK
UCB0CTL1 &= ~UCSWRST; //stop the serial clock
dataComplete = false;
}

if(!P5IN)
{
UCB0CTL1 &= ~UCSWRST; // *Initialize USCI state machine*
UCB0TXBUF = 0x00; // Dummy write to start SPI
UCB0TXBUF = 0x00;
while (!(UCB0IFG & UCRXIFG)); // USCI_B0 TX buffer ready?
data1 = UCB0RXBUF; // R15 = 00|MSB
sign = data1 >>7;
if(sign==1)
{
signExtension=11111111;
}
else
{
signExtension=00000000;
}
signExtension << 24;
data1 = data1 << 16;
while (!(UCB0IFG & UCRXIFG)); // USCI_B0 TX buffer ready?
data2 = UCB0RXBUF;
data2=data2<<8;
while (!(UCB0IFG & UCRXIFG)); // USCI_B0 TX buffer ready?
data3 = UCB0RXBUF;
data1 = data1 + data2 + data3 + signExtension; // R14 = 00|LSB
dataComplete = true; //makes sure that it only stops the SCLK once by only going inside the if statement once

}
}
}

my code is correct or not? why we use sign extension function??

Could you please email me the code for ADS1231REF interface with msp430fr4133.  

my email : pathak.sayali58@gmail.com

  • Hello sayali,

    According to the ADS1231 datasheet, SCLK polarity should be low (UCCKPL cleared) and data is captured on the second edge (UCCKPH cleared), you do not need to set UCRXIE since you are not using interrupts but otherwise your SPI initialization looks appropriate. Where did you source your code from? You need to send a dummy byte for each byte that you would like to receive from your slave device. The Precision Data Converters Forum can comment on sign extension functionality and other ADC-specific questions. Here are some Energia references that might be useful:

    www.emergingtechs.org/.../load-cell-interfacing-using-ads1231-and.html
    www.ti.com/.../slyc144

    Regards,
    Ryan
  • Hello,
    I referred a code from"precision data conversion forum-Help with SPI code for ADS1231".
    connection between ADS1231 and MSP430FR4133 :-
    DRDY'/DOUT connected to both P5.3 and P5.5, SCK-P5.1, PDWN-P2.1, SPEED-P2.0

    1)there is any need to stopping and starting the SCLK through software??
    2) after debug the code P5.5(DRDY' pin) status shows 1 in register.why?? datasheet says,data is receive when DRDY becomes low.
    according to forum i make some changes in code:-
    long int data1,data2,data4;

    P5SEL0 |= BIT1 |BIT3; // set 2-SPI pin as second function
    P2DIR |= BIT0 | BIT1;
    P2OUT |= ~BIT0; //SPEED low 10SPS
    UCB0CTLW0 |= UCSWRST; // **Put state machine in reset**
    UCB0CTLW0 |= UCMST|UCSYNC|UCMSB; // 3-pin, 8-bit SPI master
    // Clock polarity high, MSB
    UCB0CTLW0 |= UCSSEL__SMCLK; // Select SMCLK
    UCB0BR0 = 0x01; // /2,fBitClock = fBRCLK/(UCBRx+1).
    UCB0BR1 = 0; //
    UCB0CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
    P2OUT |= BIT1; //PDWN' PIN HIGH
    P5DIR&=~0x20; //


    while(!(P5IN&0x20)); // check DRDY pin goes low (P5.5)
    {
    UCB0CTL1 &= ~UCSWRST; // *Initialize USCI state machine*
    UCB0TXBUF = 0x00; // Dummy write to start SPI
    UCB0TXBUF = 0x00;

    while (!(UCB0IFG & UCRXIFG)); // USCI_B0 TX buffer ready?
    data1 = UCB0RXBUF; // R15 = 00|MSB
    data1 = data1 << 16;
    UCB0TXBUF = 0x00;
    while (!(UCB0IFG & UCRXIFG));
    data2 = UCB0RXBUF;
    data2=data2<<8;
    data4 = data1 + data2; // R14 = 00|LSB
    }
    i given the code please check the code is written right or wrong.and any modification is required from your side please correct.
    when i debug the code,the value stored in data1 variable is 0x00FF00FF??
    please tell me flowchart regarding programming?

  • As I said before, the Precision Data Converters Forum can comment on ADS1231-specific questions. It also sounds like you have a specific E2E thread regarding this specific topic, perhaps those involved would be able to give you further guidance. You should be using an oscilloscope or logic analyzer to confirm that your SPI sequence is correct and that the ADC is sending valid data. RXBUF is a byte in length so I would expect for you to shift data1 by 8 and not shift data2 at all, so when added together they provide a 16-bit value stored in data4.

    Regards,
    Ryan

**Attention** This is a public forum