刚刚在TI申请了3pcsADS1247样品 打样测试了一下发现 寄存器写进去 在读出的数据正常,读取AD值的时候不正常,读出的数据一直保持在0X7FFFFF
请问用过这个芯片的朋友,帮我看看是什么原因造成的谢谢!
#define WakeUp 0x00 //????????????
#define Sleep 0x02 //????????????
#define SYNC 0x04 //????A/D×???
#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 Reg_MUX0 0x00 //
#define Reg_VBias 0x01 //
#define Reg_MUX1 0x02 //
#define Reg_SYS0 0x03 //
#define Reg_CFC0 0x04 //
#define Reg_CFC1 0x05 //
#define Reg_CFC2 0x06 //
#define Reg_FSC0 0x07 //
#define Reg_FSC1 0x08 //
#define Reg_FSC2 0x09 //
#define Reg_IDAC0 0x0a //
#define Reg_IDAC1 0x0b //
#define Reg_GPIOCFG 0x0c //
#define Reg_GPIODIR 0x0d //
#define Reg_GPIODAT 0x0e //
#define ADS1247_MUX0 0x01 //AIN0(+)-AIN1(-)
#define ADS1247_VBias 0x00 //??????????????
#define ADS1247_MUX1 0x00 //????????REF,????????
#define ADS1247_SYS0 0x00 //·??ó1±?,5Hz
#define ADS1247_IDAC0 0x06 //1mA
#define ADS1247_IDAC1 0x0F //???÷??AIN0????1mA
#define ADS1247_DIN_CLR() GPIO_ResetBits(GPIOC,GPIO_Pin_0);
#define ADS1247_DIN_SET() GPIO_SetBits(GPIOC,GPIO_Pin_0);
#define ADS1247_SCLK_CLR() GPIO_ResetBits(GPIOC,GPIO_Pin_2);
#define ADS1247_SCLK_SET() GPIO_SetBits(GPIOC,GPIO_Pin_2);
#define ADS1247_CS_CLR() GPIO_ResetBits(GPIOC,GPIO_Pin_11);
#define ADS1247_CS_SET() GPIO_SetBits(GPIOC,GPIO_Pin_11);
#define ADS1247_DOut_CLR() GPIO_ResetBits(GPIOC,GPIO_Pin_10);
#define ADS1247_DOut_SET() GPIO_SetBits(GPIOC,GPIO_Pin_10);
#define ADS1247_DOut_Get() GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_10)
#define ADS1247_RESET_CLR() GPIO_ResetBits(GPIOC,GPIO_Pin_1);
#define ADS1247_RESET_SET() GPIO_SetBits(GPIOC,GPIO_Pin_1);
#define ADS1247_START_CLR() GPIO_ResetBits(GPIOC,GPIO_Pin_12);
#define ADS1247_START_SET() GPIO_SetBits(GPIOC,GPIO_Pin_12);
void ADS1247_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void ADS1247_Delays(unsigned int count)//6us
{
uint16_t i,j;
for(i=count;i>0;i--)
for(j=12;j>0;j--);
}
void WriteByteADS1247(unsigned char x)//8BIT
{
unsigned char ii;
// ADS1247_SCLK_SET();
for (ii=0; ii<8; ii++)
{
ADS1247_SCLK_SET();
ADS1247_Delays(20);
if(x & 0x80) { ADS1247_DIN_SET(); }
else { ADS1247_DIN_CLR(); }
ADS1247_Delays(20);
ADS1247_SCLK_CLR();
ADS1247_Delays(20);
x <<=1;
}
}
void WriteWordADS1247(unsigned int x)//16BIT
{
unsigned char ii;
// ADS1247_SCLK_SET();//SET_ADSCK;
for (ii=0; ii<16; ii++)
{
ADS1247_SCLK_SET();
ADS1247_Delays(20);
if(x & 0x8000){ ADS1247_DIN_SET(); }
else { ADS1247_DIN_CLR(); }
ADS1247_Delays(20);
ADS1247_SCLK_CLR();
ADS1247_Delays(20);
x <<=1;
}
}
void WriteDWordADS1247(unsigned long int x)//24BIT
{
unsigned char ii;
// ADS1247_SCLK_SET();
for (ii=0; ii<24; ii++)
{
ADS1247_SCLK_SET();
ADS1247_Delays(20);
if(x & 0x800000){ ADS1247_DIN_SET(); }
else { ADS1247_DIN_CLR(); }
ADS1247_Delays(20);
ADS1247_SCLK_CLR();
ADS1247_Delays(20);
x <<=1;
}
}
unsigned char ReadByteADS1247(void)//8BIT
{
unsigned char ii;
unsigned char x ;
while(ADS1247_DOut_Get());
// ADS1247_SCLK_SET();
for (ii = 0,x=0 ; ii < 8 ; ii++)
{
ADS1247_SCLK_SET();
ADS1247_Delays(20);
x<<=1;
if(ADS1247_DOut_Get())
x |= 0x01;
ADS1247_SCLK_CLR();
ADS1247_Delays(20);
}
return x;
}
unsigned int ReadWordADS1247(void)//16BIT
{
unsigned char ii;
unsigned int x ;
while(ADS1247_DOut_Get());
// ADS1247_SCLK_SET();
for (ii = 0,x=0 ; ii < 16 ; ii++)
{
ADS1247_SCLK_SET();
ADS1247_Delays(20);
x<<=1;
if (ADS1247_DOut_Get())
x |= 0x01;
ADS1247_SCLK_CLR();
ADS1247_Delays(20);
}
return x;
}
unsigned long int ReadDWordADS1247(void)//24BIT
{
unsigned char ii;
unsigned long int x ;
// ADS1247_SCLK_SET();
for (ii = 0,x = 0 ; ii < 24 ; ii++)
{
ADS1247_SCLK_SET();
ADS1247_Delays(20);
x<<=1;
if (ADS1247_DOut_Get())
x |= 0x01;
ADS1247_SCLK_CLR();
ADS1247_Delays(20);
}
//set_cs ;
return x;
}
void ResetADS1247(void)
{
unsigned char ii;
for(ii=0;ii<35;ii++)
{
ADS1247_SCLK_CLR();
ADS1247_Delays(20);
ADS1247_DIN_SET();
ADS1247_Delays(20);
ADS1247_SCLK_SET();
ADS1247_Delays(20);
}
}
unsigned char k;
void ADS1247_Configuration(void)
{
ADS1247_GPIO_Configuration();
ADS1247_CS_CLR();
ADS1247_RESET_SET()
ADS1247_Delays(20);
WriteByteADS1247(Reset);
ADS1247_Delays(1000);//6ms
WriteByteADS1247(WReg|Reg_MUX0);
WriteByteADS1247(0x00);
WriteByteADS1247(ADS1247_MUX0);
WriteByteADS1247(WReg|Reg_VBias);
WriteByteADS1247(0x00);
WriteByteADS1247(ADS1247_VBias);
WriteByteADS1247(WReg|Reg_MUX1);
WriteByteADS1247(0x00);
WriteByteADS1247(ADS1247_MUX1);
WriteByteADS1247(WReg|Reg_SYS0);
WriteByteADS1247(0x00);
WriteByteADS1247(ADS1247_SYS0);
WriteByteADS1247(WReg|Reg_IDAC0);
WriteByteADS1247(0x00);
WriteByteADS1247(ADS1247_IDAC0);
WriteByteADS1247(WReg|Reg_IDAC1);
WriteByteADS1247(0x00);
WriteByteADS1247(ADS1247_IDAC1);
WriteByteADS1247(RReg|Reg_IDAC1);
WriteByteADS1247(0x00);
k = ReadByteADS1247();
WriteByteADS1247(0x14);
// ADS1247_CS_SET();
ADS1247_START_SET();
}
unsigned int temp24;
void GetADS1247Data(void)
{
while(ADS1247_DOut_Get());
temp24 = ReadDWordADS1247();
}转载
|