打算用AD7719因为他带有200uA恒流,不知道他的抗干扰能力,和数据稳定到多少位
从ADI申请的样片到了,焊接到板子上发现无法写入寄存器的值和读出的不一样,不知道为什么,用过的帮忙看看什么问题,谢谢
#define AD7719_RCC_APB2Periph_GPIOx RCC_APB2Periph_GPIOD
#define AD7719_GPIOx GPIOD
#define AD7719_DIN_Px GPIO_Pin_13
#define AD7719_SCLK_Px GPIO_Pin_12
#define AD7719_RDY_Px GPIO_Pin_11
#define AD7719_DOut_Px GPIO_Pin_14
#define AD7719_DIN_CLR() GPIO_ResetBits(AD7719_GPIOx,AD7719_DIN_Px);
#define AD7719_DIN_SET() GPIO_SetBits(AD7719_GPIOx,AD7719_DIN_Px);
#define AD7719_SCLK_CLR() GPIO_ResetBits(AD7719_GPIOx,AD7719_SCLK_Px);
#define AD7719_SCLK_SET() GPIO_SetBits(AD7719_GPIOx,AD7719_SCLK_Px);
#define AD7719_RDY_CLR() GPIO_ResetBits(AD7719_GPIOx,AD7719_RDY_Px);
#define AD7719_RDY_SET() GPIO_SetBits(AD7719_GPIOx,AD7719_RDY_Px);
#define AD7719_RDY_Get() GPIO_ReadInputDataBit(AD7719_GPIOx, AD7719_RDY_Px)
#define AD7719_DOut_CLR() GPIO_ResetBits(AD7719_GPIOx,AD7719_DOut_Px);
#define AD7719_DOut_SET() GPIO_SetBits(AD7719_GPIOx,AD7719_DOut_Px);
#define AD7719_DOut_Get() GPIO_ReadInputDataBit(AD7719_GPIOx, AD7719_DOut_Px)
#define WriteReg 0x00//写寄存器
#define ReadReg 0x40//读寄存器
#define CommReg 0x00//通信状态寄存器
#define ModeReg 0x01//模式寄存器
#define MainControlReg 0x02//主控制寄存器
#define AuxControlReg 0x03//辅助控制寄存器
#define FilterReg 0x04//滤波寄存器
#define MainDataReg 0x05//主数据寄存器
#define AuxDataReg 0x06//辅助数据寄存器
#define IOControlReg 0x07//IO控制寄存器
#define MainOffsetReg 0x08//主失调校准寄存器
#define AuxOffsetReg 0x09//辅助失调校准寄存器
#define MainGainReg 0x0A//主增益校准寄存器
#define AuxGainReg 0x0B//辅助增益校准寄存器
#define Test1Reg 0x0C//测试寄存器1
#define Test2Reg 0x0D//测试寄存器2
#define IDReg 0x0F//ID寄存器
#define ModeRegVal 0x03//模式寄存器设置值 开启BUF 差分输入 连续转换
#define MainControlRegVal 0x88//主AIN1-AIN2 单极性 20mv
#define IOControlRegVal 0x0100//200uA在IOUT1输出
void AD7719Delay(void)
{
unsigned char i;
for(i=0;i<40;i++);
}
void AD7719_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(AD7719_RCC_APB2Periph_GPIOx, ENABLE);
GPIO_InitStructure.GPIO_Pin = AD7719_DOut_Px | AD7719_RDY_Px;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(AD7719_GPIOx, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = AD7719_DIN_Px | AD7719_SCLK_Px;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(AD7719_GPIOx, &GPIO_InitStructure);
// AD7719_CS_SET();
}
/**
* @brief 读写数据
* @param WriteBuffer
* @param ReadBuffer
* @param NumberOfByte
* @retval None
*/
void AD7719ReadWriteBuf(unsigned char* WriteBuffer, unsigned char *ReadBuffer, unsigned char NumberOfByte)
{
unsigned char WriteData, ReadData;
unsigned char i, j;
AD7719_SCLK_SET();
// AD7719_CS_CLR();
for(i=0; i<NumberOfByte; i++)
{
WriteData = *(WriteBuffer + i);
ReadData = 0;
for(j=0; j<8; j++)
{
AD7719_SCLK_CLR();
if(0x80 == (WriteData & 0x80))
{
AD7719_DIN_SET(); //Send one to SDI pin
}
else
{
AD7719_DIN_CLR(); //Send zero to SDI pin
}
WriteData = WriteData << 1;
AD7719_SCLK_SET();
ReadData = (ReadData<<1) | AD7719_DOut_Get();
}
*(ReadBuffer + i)= ReadData;
}
AD7719_SCLK_SET();
// AD7719_CS_SET();
}
void AD7719_Configuration(void)//初始化
{
unsigned char Write[3],Read[3];
AD7719_GPIO_Configuration();
DelayMs(10);
Write[0] = WriteReg|ModeReg;//
Write[1] = ModeRegVal;
AD7719ReadWriteBuf(Write,Read,2);
DelayMs(1);
Write[0] = WriteReg|MainControlReg;
Write[1] = MainControlRegVal;
AD7719ReadWriteBuf(Write,Read,2);
DelayMs(1);
Write[0] = WriteReg|IOControlReg;
Write[1] = IOControlRegVal>>8;
Write[2] = IOControlRegVal&0xFF;
AD7719ReadWriteBuf(Write,Read,3);
DelayMs(1);
while(AD7719_RDY_Get());
Write[0] = ReadReg|ModeReg;//
AD7719ReadWriteBuf(Write,Read,1);
DelayMs(1);
Write[0] = 0xFF;//
AD7719ReadWriteBuf(Write,Read,1);
while(AD7719_RDY_Get());
Write[0] = ReadReg|MainControlReg;//
AD7719ReadWriteBuf(Write,Read,1);
DelayMs(1);
Write[0] = 0xFF;//
AD7719ReadWriteBuf(Write,Read,1);
while(AD7719_RDY_Get());
Write[0] = ReadReg|IOControlReg;//
AD7719ReadWriteBuf(Write,Read,1);
DelayMs(1);
Write[0] = 0xFF;//
AD7719ReadWriteBuf(Write,Read,2);
while(AD7719_RDY_Get());
// Write[0] = ReadReg|MainDataReg;
// AD7719ReadWriteBuf(Write,Read,1);
// DelayMs(1);
}
unsigned long AD7719_GetValue(void)
{
unsigned char Write[3],Read[3];
// while(AD7719_RDY_Get());
Write[0] = ReadReg|IOControlReg;//
AD7719ReadWriteBuf(Write,Read,1);
DelayMs(1);
Write[0] = 0xFF;//
Write[1] = 0xFF;//
Write[2] = 0xFF;//
AD7719ReadWriteBuf(Write,Read,3);
// while(AD7719_RDY_Get());
return 0;
}
转载
|