• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Data Converters » Precision Data Converters » Precision Data Converters Forum » ADC1248 Problem
Share
Precision Data Converters
  • Forum
  • Files
  • E2E Wiki
Options
  • Subscribe via RSS
Check out
The Signal blog
  • $core_v2_blog.Current.Name

    Grounding Principles

    Posted 4 days ago
    by Bruce Trump
    In a previous blog on supply bypassing , I cautioned that poor...
  • $core_v2_blog.Current.Name

    Handy Gadgets and Resistor Divider Calculations

    Posted 11 days ago
    by Bruce Trump
    Handy gadgets make our engineering life easier—the little...
  • $core_v2_blog.Current.Name

    Chopper Op Amps—are they really noisy?

    Posted 19 days ago
    by Bruce Trump
    Chopper op amps offer very low offset voltage and dramatically...

Forums

ADC1248 Problem

This question is answered
sujit naphad
Posted by sujit naphad
on Mar 14 2012 08:09 AM
Prodigy30 points

hi 

     I am facing one problem during writing code for MSP430F5438 to connect ADC1248.I have use port4 as GPIO.M getting data on SDI line which is sending data to ADC.M putting my code down plz tell me the correction in receive function.

//Sample test program for MSP430-5438STK
//Test RS
//Return echo ot RS

#include "io430.h"

#define OSC_FREQ 18000000
#define BAUDRATE 9600


#define WAKEUP 0x00
#define SLEEP 0x02
#define SYNC 0x04
#define RESET 0x06
#define NOP 0xFF
#define RDATA 0x12
#define RDATAC 0x14
#define SDATAC 0x16
#define RREG 0x20
#define WREG 0x40
#define SYSOCAL 0x60
#define SYSGCAL 0x61
#define SELFOCAL 0x62
#define cell 0x22

//unsigned char high_byte,low_byte;

unsigned char put,byte;
unsigned char reg;

void CLOCK_XT2_Init()
{
int timeout = 5000;
P11DIR = P11DIR | 0x02 | 0x04; //set P11.1 & P11.2 as output
P11SEL = P11SEL | 0x02 | 0x04; //set P11.1 & P11.2 as MCLK/SMCLK function
P5SEL = P5SEL | 0x04 | 0x08; //set P5.2 & P5.3 as XT2IN/XT2OUT

UCSCTL6 = UCSCTL6 & (~XT2OFF); //set XT2OFF=0 (bit8 = 0) --> enable XT2
UCSCTL3 = UCSCTL3 | 0x20; //set SELREF = 010 --> FLL clock source = REFOCLK
UCSCTL4 = UCSCTL4 | 0x200; //set SELA = 010 --> ACLK=REFO

do
{
if (!(UCSCTL7 & 0x08)) break;
UCSCTL7 = UCSCTL7 & ~(0x0F); // Clear XT2,XT1,DCO fault flags
SFRIFG1 = SFRIFG1 & ~(0x02); // Clear fault flags (SFRIFG1.OFIFG = 0)
timeout--;
}
while ((SFRIFG1 & 0x02) && timeout); // Test oscillator fault flag

UCSCTL5 = UCSCTL5 | 0x0005; //MCLK/SMCLK divisor = 32

UCSCTL4 = UCSCTL4 | 0x55; //SMCLK=MCLK=XT2
UCSCTL4 = ((UCSCTL4 & ~0x100) & ~0x200) & ~0x400; //ACLK=XT1 (SELA = 0b000)
}


void UART2_Init(unsigned long baud)
{
float n, x;
P9DIR = P9DIR | 1<<4; //set P9.4=1 (Transmitter) as output
P9DIR = P9DIR & ~(1<<5); //set P9.5=0 (Receiver) as input
P9SEL = P9SEL | 1<<4 | 1<<5; //set P9.4=1 & P9.5=1 as TX/RX


UCA2CTL1 = UCA2CTL1 | 0x01; //UCSWRST = 1 (bit0 = 1) //page 417

UCA2CTL1 = (UCA2CTL1 | 1<<7) & ~(1<<6); //select SMCLK as BaudRate source clock (bit6 = 1; bit7 = 1)

//calculate registers for the BaudRate +

UCA2MCTL = UCA2MCTL | 0x01; //UCOS16 = 1
//calculate UCBR
n = OSC_FREQ / baud;
UCA2BR0 = (int)(n/16) % 256;
UCA2BR1 = (int)(n/16) / 256;

//caluclate UCBRS
x = (int)((n-(int)(n))*8+0.5);
UCA2MCTL = UCA2MCTL | (int)(x)<<1;

//caluclate UCBRF
x = (int)(((n/16 - (int)(n/16))*16) + 0.5);
UCA2MCTL = UCA2MCTL | (int)(x)<<4;

//calculate registers for the BaudRate -

UCA2CTL0 = 0x00; //Set Format Frame: 8 bit data; no parity; 1 stop bit

UCA2CTL1 = UCA2CTL1 & ~(0x01); //UCSWRST = 0 (bit0 = 0) //page 417
}

unsigned char UART2_Receive()
{
// if (UCA2IFG & 0x01)
//return UCA2RXBUF;
// else
// return 0;
put=UCA2RXBUF;
}

void UART2_Transmit ()
{
//while (!(UCA2IFG & 0x02));
UCA2TXBUF ;//= cell
}

/*-------------Delay----------------------*/

void Delay(void)
{
int j;
for (j=0; j<10000; j++)
for (j=0; j<10000; j++);
}


/*------------transfer byte-------------------------*/
void transfer_byte(char data)
{
unsigned char x;
P4OUT &=~ 0x08; /*clear SCLK*/
for(x=0;x<8;x++)
{

if((data & 0x80)==0)
{
P4OUT &=~ 0x04;
}
else
P4OUT |= 0x04;

P4OUT |= 0x08; /*SET SCLK*/
P4OUT &=~ 0x08; /*clear SCLK*/
data = data<<1;
}
}



/*------------------receive_byte------------------------------------*/
unsigned char receive_byte()
{
{
unsigned char y,a;

for(y=0;y<8;y++)
{

a=(P4OUT & 0x02); //
P4OUT |= 0x08; /*SET SCLK*/
/*if((reg & 0x80)==0)
{

reg==0;
}
else
{
reg==1;
}*/
reg=a;
reg = reg<<1;
P4OUT &=~ 0x08; /*clear SCLK*/

}

}
return reg;
}

/*--------------------------write_to_register---------------------------------*/
void write_to_register(char byte) //char command_first,char command_second
{
P4OUT &=~ 0x01; /* Clear CSb */
//transfer_byte(command_first);
// transfer_byte(command_second);
transfer_byte(0x22);
P4OUT |= 0x01; /* Set CSb */

}

/*---------------------Read_register---------------------------*/

void read_register() //char command_first,char command_second
{
P4OUT &=~ 0x01; /*Clear CSb*/
// transfer_byte(command_first); /*Send Command*/
// transfer_byte(command_second); /*Send Command*/
put=receive_byte();
P4OUT |= 0x01; /*Set CSb*/
}


int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
//char c;

CLOCK_XT2_Init();
UART2_Init(BAUDRATE);


P4DIR |= 0x01; //--------------set as a out put.
P4SEL &=~ 0x01; //--------------set as GPIO Pin 4.0-----------
P4OUT &=~ 0x01; //--------------set pin as low i.e CS=low

P4DIR &=~ 0x02; //--------------set as a in put
P4SEL &=~ 0x02; //--------------set as GPIO Pin 4.1-----------
P4OUT &=~ 0x02; //--------------set pin as low i.e DRDY/DOUT

P4DIR |= 0x04; //--------------set as a out put.
P4SEL &=~ 0x04; //--------------set as GPIO Pin 4.2-----------
P4OUT &=~ 0x04; //--------------set pin as low i.e DIN=low

P4DIR |= 0x08; //--------------set as a out put.
P4SEL &=~ 0x08; //--------------set as GPIO Pin 4.3-----------
P4OUT &=~ 0x08; //--------------set pin as low i.e SCLK=low


P4DIR |= 0x10; //--------------set as a out put.
P4SEL &=~ 0x10; //--------------set as GPIO Pin 4.4-----------
P4OUT &=~ 0x10; //--------------set pin as low i.e START=low

P4DIR |= 0x20; //--------------set as a out put.
P4SEL &=~ 0x20; //--------------set as GPIO Pin 4.5-----------
P4OUT |= 0x20; //--------------set pin as low


P4OUT |= 0x10; //start high
Delay();
P4OUT &=~ 0x10; //start low
Delay();





while (1)
{

write_to_register(0x11); //0x40,0x00,
read_register(); //0x40,0x00
// UCA2TXBUF=transfer_byte(put);

UART2_Transmit();
UART2_Receive();



}
}
Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • Bob Benjamin
    Posted by Bob Benjamin
    on Mar 14 2012 12:55 PM
    Verified Answer
    Verified by Tom Hendrick
    Mastermind34195 points

    Sujit,

    If I understand correctly, you are trying to bit-bang the port pins.  Is this because you cannot use one of the SPI peripherals?  If I'm following the code, you are not giving the full command to the device.  You need to give the WREG command which will include the starting register you wish to write and the number of registers you wish to write (less one).  This will be followed by the register data.  To write one register you need to send three bytes of data.  To write to the SYS0 register, for example, to change the gain to 128 and the data rate to 640 sps the bytes would be:

    0x43     // this is write register 3

    0x00     // write only one register (1-1=0)

    0x77     // write gain=128 and data rate=640

    All three bytes must have CS low throughout the total transfer (in other words it cannot toggle.)

    It would be helpful to send me scope pictures of the communication, as that will show me the timing and the actual data being transmitted.

    Best regards,

    Bob B

    ADS1248
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use