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.

Reading/Writing register/A2D data - ADS131E08

Other Parts Discussed in Thread: MSP430F5418, ADS131E08

Hello,

I have the ADS131E08 EVM attached to an MSP430F5418. I need to read the A2D using SPI - UCSB0SPI.

The wiring is as follows:

MSP430 f 5418 Desc. EVM Board
P3.0 SPI_CS JP8.2
P1.1 SPI_Start JP9.2
P3.1 SPI_IN J1.11
P3.2 SPI_OUT J1.13
P1.2 SPI_DRDY J1.15
P3.3 SPI_CLK J1.3
  GND J1.18

I'm trying to read the registers of the ADS131

7380.ADS_131_code.c
unsigned char TempData[20];

//******************************************************************************
// ADS131/MSP430x5418 Demo - ADS_131 to MSP430 communication via SPI  
//                    
//
// Description: Use of the MSP430 USCI A0 peripheral for setting up and 
//    communicating to the ADS_131 
//    
//    
//                                                   
//                 MSP430x5418
//             ------------------                        
//         /|\|                  |                       
//          | |                  |                       
//          --|RST           P3.2|<-- MISO (DOUT)           
//            |                  |                                         
//            |              P3.1|--> MOSI (DIN)
//            |                  |  
//            |              P3.3|--> SCLK
//            |                  | 
//            |              P1.2|<-- INT (DRDY) 
//            |                  | 
//            |              P3.0|--> CS 
//
//   R. Benjamin
//   Texas Instruments Inc.
//   May 2013
//   
//******************************************************************************
//+-----------------------------------------------------------------------------+
//|  Source: main.c, v1.0 2013/05/28                                           |
//------------------------------------------------------------------------------+   

#include <msp430f5418.h>
#include "ADS1220.h"

// Function declarations
void Init_StartUp(void);
void SPIinit(void);

// Global variable
int dflag = 0;
long tData[8][500];

/*----------------------------------------------------------------------------+
| Main Routine                                                                |
+----------------------------------------------------------------------------*/
void main(void)
{
	int idx = 0;
	WDTCTL = WDTPW + WDTHOLD;	    // Stop watchdog timer
	
    Init_StartUp();                 // Initialize device
	ADS_131_Init();					// Initializes the SPI port pins as well as control
    ADS_131_Config();				// Set base configuration for ADS1x20 device
} //main()

/*----------------------------------------------------------------------------+
| System Initialization Routines                                              |
+----------------------------------------------------------------------------*/

// Initializes the clocks.  Starts the DCO at USB_MCLK_FREQ (the CPU freq set with the Desc 
// Tool), using the REFO as the FLL reference.  Configures the high-freq crystal, but 
// doesn't start it yet.  Takes some special actions for F563x/663x.  
void Init_Clock(void)
{
	P5SEL |= 0x0C;
	P5DIR |= BIT4+BIT5;
	UCSCTL1 = DCORSEL_6;
	UCSCTL2 = FLLD_1+1;
	UCSCTL3 = SELREF__XT2CLK;
	UCSCTL6 = XT2DRIVE1;


	// Start the FLL, which will drive MCLK (not the crystal)
	//Init_FLL(USB_MCLK_FREQ/1000, USB_MCLK_FREQ/32768);
	//Init_FLL(USB_MCLK_FREQ/1000, USB_MCLK_FREQ/12000000);
	UCSCTL4  = SELA_4 + SELS_4 + SELM_4;      // ACLK=TX2  SMCLK=TX2   MCLK=TX2
	P2SEL |= BIT2;
	P2DIR |= BIT2;
	__bis_SR_register(GIE+OSCOFF);
}

//----------------------------------------------------------------------------

void Init_Ports(void)
{
	// Initialization of ports all unused pins as outputs with low-level

	// set all ports  to low on all pins
	P1OUT 	= 	0x04;
	P1DIR 	=	0xFF;
	P2OUT	= 	0x00;
	P2DIR	|=	0x3F;
	P3OUT	= 	0x00;
	P3DIR	|=	0x07;
	P4OUT	=	0x00;
	P4DIR	|=	0xFF;
	P5OUT	=	0x00;
	P5DIR	|=	0x33;
	P6OUT	=	0x00;
	P6DIR	=	0xFF;
    
}

//----------------------------------------------------------------------------

// Sets the USCI SPI peripheral to use B0
void SPIinit(void)
{
	UCB0CTL1 |= UCSWRST;						// Hold peripheral in reset
	UCB0CTL0 = UCMST + UCSYNC + UCMSB;			// SPI master, synchronous
	UCB0CTL1 = UCSSEL_2 + UCSWRST;				// Use SMCLK for bit rate clock and keep in reset
	UCB0BR0 = 12;								// SMCLK/12 = SCLK (2MHz)
	UCB0CTL1 &= ~UCSWRST; 						// Release peripheral for use
}

//----------------------------------------------------------------------------

void Init_StartUp(void)
{
    __disable_interrupt();               // Disable global interrupts
    
    Init_Ports();                        // Init ports (do first ports because clocks do change ports)
  //  SetVCore(3);                         // USB core requires the VCore set to 1.8 volt, independ of CPU clock frequency
    Init_Clock();
    SPIinit();

    __enable_interrupt();                // enable global interrupts
}

void ADS_131_Init(void)
{
	P3SEL |= ADS1220_DIN + ADS1220_DOUT + ADS1220_SCLK;
	P1SEL &= ~(ADS1220_DRDY);
	P3SEL &= ~(ADS1220_CS);
	 
	// define initial states
	P3OUT |=  (ADS1220_CS); 					// CS is really 'not' CS, so it should be disabled high
	
	// define inputs
	P1DIR &= ~(ADS1220_DRDY);					// DRDY is an input to the micro
	P1IES |= ADS1220_DRDY;						// and should be used as an interrupt to retrieve data
	// define outputs
	P3DIR |= ADS1220_CS;
   
   return;
}

void ADS_131_AssertCS( int fAssert)
{
   if (fAssert)
		P3OUT &=  ~(ADS1220_CS);
   else
		P3OUT |=  (ADS1220_CS);
      
}

void ADS_131_SendByte(unsigned char Byte)
{
	char dummy;
	while(!(UCB0IFG & UCTXIFG));
	UCB0TXBUF = Byte;
	while(!(UCB0IFG & UCRXIFG));
	dummy = UCB0RXBUF;
}

unsigned char ADS_131_ReceiveByte(void)
{
   unsigned char Result = 0;
   
	while(!(UCB0IFG & UCTXIFG));	// Make sure nothing is currently transmitting
	UCB0TXBUF = 0xff;		 	// Send out NOP to initiate SCLK
	while(!(UCB0IFG & UCRXIFG));	// Wait until all data is transmitted (received)
	Result = UCB0RXBUF;	// Capture the receive buffer
		
	return Result;
}

void ADS_131_ReadRegister(int StartAddress, int NumRegs, unsigned char *pData)
{
   int i;

	// assert CS to start transfer
	ADS_131_AssertCS(1);
   
	// send the command byte
	//    Register Read Commands
	//  RREG |  Read n nnnn registers starting at address r rrrr |  001r rrrr (2xh) | 000n nnnn
	//
	//           r rrrr = starting register address for read and write opcodes.
	//           n nnnn = number of registers to be read or written – 1.
	//           For example, to read or write three registers, set n nnnn = 0 0010.

	ADS_131_SendByte(0x20 | (StartAddress & 0x1F));
	ADS_131_SendByte((NumRegs-1) & 0x1F);
   
	// get the register content
	for (i=0; i< NumRegs; i++)
	{
		*pData++ = ADS_131_ReceiveByte();
	}
   
	// de-assert CS
	ADS_131_AssertCS(0);
	
	return;
}

// ADS1220 Initial Configuration
void ADS_131_Config(void)
{
	ADS_131_ReadRegister(0, 1, &(TempData[0]));
	ADS_131_ReadRegister(0, 1, &(TempData[1]));
	ADS_131_ReadRegister(0, 1, &(TempData[2]));
	ADS_131_ReadRegister(0, 1, &(TempData[3]));
	ADS_131_ReadRegister(0, 1, &(TempData[4]));
}
, and I'm not getting correct values. Also, if I read register 0 a few times, I get different values.

Attached is the code I'm using to setup the SPI and registers. I'd appreciate any help.

Thanks,

Mechi

7610.ADS_131_code.c
unsigned char TempData[20];

//******************************************************************************
// ADS131/MSP430x5418 Demo - ADS_131 to MSP430 communication via SPI  
//                    
//
// Description: Use of the MSP430 USCI A0 peripheral for setting up and 
//    communicating to the ADS_131 
//    
//    
//                                                   
//                 MSP430x5418
//             ------------------                        
//         /|\|                  |                       
//          | |                  |                       
//          --|RST           P3.2|<-- MISO (DOUT)           
//            |                  |                                         
//            |              P3.1|--> MOSI (DIN)
//            |                  |  
//            |              P3.3|--> SCLK
//            |                  | 
//            |              P1.2|<-- INT (DRDY) 
//            |                  | 
//            |              P3.0|--> CS 
//
//   R. Benjamin
//   Texas Instruments Inc.
//   May 2013
//   
//******************************************************************************
//+-----------------------------------------------------------------------------+
//|  Source: main.c, v1.0 2013/05/28                                           |
//------------------------------------------------------------------------------+   

#include <msp430f5418.h>
#include "ADS1220.h"

// Function declarations
void Init_StartUp(void);
void SPIinit(void);

// Global variable
int dflag = 0;
long tData[8][500];

/*----------------------------------------------------------------------------+
| Main Routine                                                                |
+----------------------------------------------------------------------------*/
void main(void)
{
	int idx = 0;
	WDTCTL = WDTPW + WDTHOLD;	    // Stop watchdog timer
	
    Init_StartUp();                 // Initialize device
	ADS_131_Init();					// Initializes the SPI port pins as well as control
    ADS_131_Config();				// Set base configuration for ADS1x20 device
} //main()

/*----------------------------------------------------------------------------+
| System Initialization Routines                                              |
+----------------------------------------------------------------------------*/

// Initializes the clocks.  Starts the DCO at USB_MCLK_FREQ (the CPU freq set with the Desc 
// Tool), using the REFO as the FLL reference.  Configures the high-freq crystal, but 
// doesn't start it yet.  Takes some special actions for F563x/663x.  
void Init_Clock(void)
{
	P5SEL |= 0x0C;
	P5DIR |= BIT4+BIT5;
	UCSCTL1 = DCORSEL_6;
	UCSCTL2 = FLLD_1+1;
	UCSCTL3 = SELREF__XT2CLK;
	UCSCTL6 = XT2DRIVE1;


	// Start the FLL, which will drive MCLK (not the crystal)
	//Init_FLL(USB_MCLK_FREQ/1000, USB_MCLK_FREQ/32768);
	//Init_FLL(USB_MCLK_FREQ/1000, USB_MCLK_FREQ/12000000);
	UCSCTL4  = SELA_4 + SELS_4 + SELM_4;      // ACLK=TX2  SMCLK=TX2   MCLK=TX2
	P2SEL |= BIT2;
	P2DIR |= BIT2;
	__bis_SR_register(GIE+OSCOFF);
}

//----------------------------------------------------------------------------

void Init_Ports(void)
{
	// Initialization of ports all unused pins as outputs with low-level

	// set all ports  to low on all pins
	P1OUT 	= 	0x04;
	P1DIR 	=	0xFF;
	P2OUT	= 	0x00;
	P2DIR	|=	0x3F;
	P3OUT	= 	0x00;
	P3DIR	|=	0x07;
	P4OUT	=	0x00;
	P4DIR	|=	0xFF;
	P5OUT	=	0x00;
	P5DIR	|=	0x33;
	P6OUT	=	0x00;
	P6DIR	=	0xFF;
    
}

//----------------------------------------------------------------------------

// Sets the USCI SPI peripheral to use B0
void SPIinit(void)
{
	UCB0CTL1 |= UCSWRST;						// Hold peripheral in reset
	UCB0CTL0 = UCMST + UCSYNC + UCMSB;			// SPI master, synchronous
	UCB0CTL1 = UCSSEL_2 + UCSWRST;				// Use SMCLK for bit rate clock and keep in reset
	UCB0BR0 = 12;								// SMCLK/12 = SCLK (2MHz)
	UCB0CTL1 &= ~UCSWRST; 						// Release peripheral for use
}

//----------------------------------------------------------------------------

void Init_StartUp(void)
{
    __disable_interrupt();               // Disable global interrupts
    
    Init_Ports();                        // Init ports (do first ports because clocks do change ports)
  //  SetVCore(3);                         // USB core requires the VCore set to 1.8 volt, independ of CPU clock frequency
    Init_Clock();
    SPIinit();

    __enable_interrupt();                // enable global interrupts
}

void ADS_131_Init(void)
{
	P3SEL |= ADS1220_DIN + ADS1220_DOUT + ADS1220_SCLK;
	P1SEL &= ~(ADS1220_DRDY);
	P3SEL &= ~(ADS1220_CS);
	 
	// define initial states
	P3OUT |=  (ADS1220_CS); 					// CS is really 'not' CS, so it should be disabled high
	
	// define inputs
	P1DIR &= ~(ADS1220_DRDY);					// DRDY is an input to the micro
	P1IES |= ADS1220_DRDY;						// and should be used as an interrupt to retrieve data
	// define outputs
	P3DIR |= ADS1220_CS;
   
   return;
}

void ADS_131_AssertCS( int fAssert)
{
   if (fAssert)
		P3OUT &=  ~(ADS1220_CS);
   else
		P3OUT |=  (ADS1220_CS);
      
}

void ADS_131_SendByte(unsigned char Byte)
{
	char dummy;
	while(!(UCB0IFG & UCTXIFG));
	UCB0TXBUF = Byte;
	while(!(UCB0IFG & UCRXIFG));
	dummy = UCB0RXBUF;
}

unsigned char ADS_131_ReceiveByte(void)
{
   unsigned char Result = 0;
   
	while(!(UCB0IFG & UCTXIFG));	// Make sure nothing is currently transmitting
	UCB0TXBUF = 0xff;		 	// Send out NOP to initiate SCLK
	while(!(UCB0IFG & UCRXIFG));	// Wait until all data is transmitted (received)
	Result = UCB0RXBUF;	// Capture the receive buffer
		
	return Result;
}

void ADS_131_ReadRegister(int StartAddress, int NumRegs, unsigned char *pData)
{
   int i;

	// assert CS to start transfer
	ADS_131_AssertCS(1);
   
	// send the command byte
	//    Register Read Commands
	//  RREG |  Read n nnnn registers starting at address r rrrr |  001r rrrr (2xh) | 000n nnnn
	//
	//           r rrrr = starting register address for read and write opcodes.
	//           n nnnn = number of registers to be read or written – 1.
	//           For example, to read or write three registers, set n nnnn = 0 0010.

	ADS_131_SendByte(0x20 | (StartAddress & 0x1F));
	ADS_131_SendByte((NumRegs-1) & 0x1F);
   
	// get the register content
	for (i=0; i< NumRegs; i++)
	{
		*pData++ = ADS_131_ReceiveByte();
	}
   
	// de-assert CS
	ADS_131_AssertCS(0);
	
	return;
}

// ADS1220 Initial Configuration
void ADS_131_Config(void)
{
	ADS_131_ReadRegister(0, 1, &(TempData[0]));
	ADS_131_ReadRegister(0, 1, &(TempData[1]));
	ADS_131_ReadRegister(0, 1, &(TempData[2]));
	ADS_131_ReadRegister(0, 1, &(TempData[3]));
	ADS_131_ReadRegister(0, 1, &(TempData[4]));
}