Part Number: ADS1231
Other Parts Discussed in Thread: MSP430F5529,
Hello,
I'm using the following code to communicate between an ADS1231 and MSP430F5529 in my weight scale design. The resulting data is shown below. As you can see, the last two bytes of each data point are consistent as intended, but the first byte varies. What is the reason for this inconsistency? Does the SPI protocol have a problem with the first byte of transmission? Any help is very appreciated.
/*
* main.c
*
* Updated on: Oct 22, 2020
* Author: Yamen Alimam
*/
#include <msp430.h>
#include <stdint.h>
#include <stdio.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // hold watchdog timer
UCB0CTL1 |= UCSWRST; // software reset enable
P3SEL = BIT1 + BIT2; // configure SPI pins (P3.1 = MISO, P3.2 = SCLK)
P2DIR |= BIT2 + BIT3; // P2.2 = SPEED, P2.3 = PWDN, outputs
P2OUT = 0x08; // 10 SPS, active
UCB0CTL0 = UCMST + UCSYNC + UCMODE_0 + UCMSB; // master mode, msb first, synchronous
UCB0CTL1 |= UCSSEL_3; // select SMCLK (1 MHz)
UCB0CTL1 &= ~UCSWRST; // initialize SPI interface
int32_t data1, code;
int16_t data2;
int8_t data3;
while (1)
{
if((P1IN & 0x08) == 0)
{
while (!(UCB0IFG & UCTXIFG));
UCB0TXBUF = 0x21;
while (!(UCRXIFG)); // if RX operation is not complete, continue
data1 = UCB0RXBUF;
while (!(UCB0IFG & UCTXIFG));
UCB0TXBUF = 0x22;
while (!(UCRXIFG));
data2 = UCB0RXBUF;
while (!(UCB0IFG & UCTXIFG));
UCB0TXBUF = 0x23;
while (!(UCRXIFG));
data3 = UCB0RXBUF;
code = (data1 << 16) + (data2 << 8) + data3 + 0x800000;
code &= 0x00ffffff;
printf("The code is %lx\n", code);
}
}
}