TI中文支持网
TI专业的中文技术问题搜集分享网站

ADS1255大神看过来呀!看过来!!

出现的问题:DRDY一直是高电平!!

电路图如图1所示:(为芯片资料上的)

图1

程序代码如下:

#include <msp430x14x.h>
#include "ads1255.h"

union{long rlong;struct{unsigned char lbyte; //低字节unsigned char mbyte; //中间字节unsigned char hbyte; //高字节unsigned char zbyte; //符号}Bytes;
} Adc_result;

unsigned char Write_SPI_One_Byte(unsigned char Byte) //采用MSP430系列单片机的SPI通信模式向ADS1255写入一个字节
{	
	U0TXBUF = Byte;// 发送一个字节 
	while(!(U0TCTL & TXEPT));//检测是否发送完毕
	return U0TXBUF;
}


void Write_SPI_Several_Byte(unsigned char length,unsigned char* pSend)//采用SPI通信模式向ADS1255写入多个字节
{
	while(length--)//检测是否发送完毕
	{
		*pSend = Write_SPI_One_Byte(*pSend); 
		pSend++;//指针自加
	}
}

void Write_Ads1255_Reg(unsigned char addr,unsigned char data)//往一个寄存器里写数据,addr为要写寄存器的地址, data为要往寄存器里写入的值
{	unsigned char send[] = {0x50,0x00,0x00};
	send[0] |= addr;
	send[2] |= data;
	Write_SPI_Several_Byte(sizeof(send),send);
}

void Init_Ads1255(void)//初始化ADS1255
{
	while(P2IN & BIT2);
	Write_Ads1255_Reg(0x00,0xf4);//STATUS REGISTER:Auto-Calibration Enabled,Analog Input Buffer Disabled
	while(P2IN & BIT2);	
	//Write_Ads1255_Reg(ADS1255_MUX,0x08);	//AIN0 is Positive,single-ended measurements//此处输入模式选择为单极输入模式AIN0为正输入端,
	Write_Ads1255_Reg(0x01,0x01);	//Input Multiplexer Control Register:AIN0 is Positive,AIN1 is Negative,differential measurements//此处输入模式选择为差分输入模式AIN0为正输入端,AIN1为负输入端while(P2IN & BIT2);	
	Write_Ads1255_Reg(0x02,0x00);	//此处0x00为关闭16脚的时钟输出,并选择增益为Gain=1(此时分辨率最高为25.3位)//Gain的最大值可设置为64,但此时分辨率就会降低为22.5位	
	while(P2IN & BIT2);	
	Write_Ads1255_Reg(0x03,0xf0);	//指定A/D的数据采样速率	
	while(P2IN & BIT2);	
	Write_Ads1255_Reg(0x04,0x00);	//GPIO控制寄存器
}

void Read_Ads1255_Reg(unsigned char addr)//读一个寄存器
{
	unsigned char send[] = {0x10,0x00};
	send[0] |= addr;
	Write_SPI_Several_Byte(sizeof(send),send);
}

void Read_Ads1255_Data(unsigned char Continuously)//读一个寄存器
{
	if(Continuously) Write_SPI_One_Byte(0x03);		//连续读取数据
	else Write_SPI_One_Byte(0x01);
}


void Set_Ads1255_Selfcal(void)//自动校准
{
	Write_SPI_One_Byte(0xf0);//SELFCAL command byte(in order to get the best performance)
}

void Set_Ads1255_Sync(void)
{
	Write_SPI_One_Byte(0xfc);//sync command byte
}

void Set_Ads1255_Standby(void)
{
	Write_SPI_One_Byte(0xfd);//standby command byte	
}

void Set_Ads1255_Wakeup(void)
{
	Write_SPI_One_Byte(0xff);//wakeup command byte(0xff can too)
}

void Set_Ads1255_Reset(void)
{
	Write_SPI_One_Byte(0xfe);//Reset to Power-Up Values
}

long int Ads1255(void)
{
	int ival;
	long int adresult;
	while(!(P2IN & BIT2));
	while(P2IN & BIT2);	//DRDY信号为低表示AD转换完成	
	Read_Ads1255_Data(0);	//read data	

	for(ival = 0; ival < 20; ival++);

	Write_SPI_One_Byte(0x05);		
	Adc_result.Bytes.hbyte = U0RXBUF;

	Write_SPI_One_Byte(0x05);
 	Adc_result.Bytes.mbyte = U0RXBUF;

	Write_SPI_One_Byte(0x05);
	Adc_result.Bytes.lbyte = U0RXBUF;
	
	Adc_result.Bytes.zbyte = 0x00;	
	if(Adc_result.Bytes.hbyte & 0x80) Adc_result.Bytes.zbyte = 0xff;	
	adresult = Adc_result.rlong;
	return adresult;
}

float Sample(unsigned char count)//电压采样及计算函数
{
	unsigned char c;
	long int adresult, sum = 0;//用于临时保存电压份数值和电压份数累加值
	float result = 0;
	for(c = 0; c < count; c++)//cout用于指定电压采样的次数
	{
		adresult = Ads1255();//将从芯片中读取的电压份数保存到变量adresult中
		sum = sum + adresult;//将从芯片中读取的电压份数累加到变量sum中		
	}
	result = sum / count;//为得到准确的电压份数值需要用电压份数累加值除以采样的次数以得到平均电压值份数result = 59.3686 * result / 100000;//此处测试的实际参考电压为V。return result;
}

void Rest_ad1255()
{/***********以下初始化ADS1255的程序**************/P2DIR &= ~BIT2;P3DIR |= 0;P3SEL |= 0;P3SEL |= BIT3 + BIT2 + BIT1;// Setup P3 for SPI modeU0CTL = CHAR + SYNC + MM + SWRST;  // 8-bit, SPI, Master,Software reset enableU0TCTL = SSEL0 + SSEL1 + STC;// SMCLK, Normal polarity, 3-wireU0BR0 = 0x002;// SPICLK = SMCLK/2U0BR1 = 0x000;U0MCTL = 0x000;ME1 = USPIE0;// 模块允许U0CTL &= ~SWRST;// SPI允许Set_Ads1255_Reset();//ADS1255复位while(P2IN & BIT2);Write_Ads1255_Reg(0x04,0x03);while(P2IN & BIT2);Write_Ads1255_Reg(0x04,0x00);while(P2IN & BIT2);Write_Ads1255_Reg(0x04,0x03);while(P2IN & BIT2);Write_Ads1255_Reg(0x04,0x00);Set_Ads1255_Reset();Set_Ads1255_Selfcal();Init_Ads1255();
}

user151383853:

DRDY一直是高电平!!    我看问题不见得在软件方面, 先检查和验证一下硬件, 包括焊接质量

xing:

回复 user151383853:

谢谢,我再排查一下。

大神,你推测是哪里最有可能出问题呢?

Martin:

请检查硬件连接是否正常,包括电源、参考等电压

请检查通信是否正常,可以尝试读写内部的寄存器,看看是否正常

可以参考图19-21看看时序是否正确。

xing:

回复 Martin:

你好!我按照您的建议试了一下,用示波器查看DOUT引脚情况,发现它一直为低电平

请问这是什么原因呢?

谢谢

赞(0)
未经允许不得转载:TI中文支持网 » ADS1255大神看过来呀!看过来!!
分享到: 更多 (0)