Other Parts Discussed in Thread: ADS1231, MSP430FR4133, 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