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.
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,
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?
**Attention** This is a public forum