最近有个项目用到AD7190 AD7190是SPI器件,按照ADI公司给出的例程,模拟SPI时序,想读器件的ID来调通和CPU之间的通信,现在的情况是读不到ID,所以怀疑通信压根就没通,驱动是例程,时序应该没有问题,现在不知道往哪方面找问题,头疼死了!附件是AD7190的驱动程序和硬件原理图,请大家帮我看看 搞了几天了 实在没办法了!用的是STM32,
贴出驱动程序:
SCLK 配置为开漏输出 外加上拉到5V
DIN 配置为推挽输出
DOU 配置为浮空输入
CS 配置为推挽输出
//void WriteToAD7190(unsigned char count,unsigned char *buf);
//---------------------------------
//Function that writes to the AD7190 via the SPI port.
//--------------------------------------------------------------------------------
void WriteToAD7190(unsigned char count, unsigned char *buf)
{unsigned char ValueToWrite = 0; unsigned char i = 0;
unsigned char j = 0;
SetSclk;
delay(2);
SetCs;
delay(2);
ClrCs;
delay(3);
for(i=count;i>0;i--)
{
ValueToWrite = *(buf + i - 1);
for(j=0; j<8; j++)
{
ClrSclk;
if(0x80 == (ValueToWrite & 0x80))
{
SetDin; //Send one to SDO pin
}
else
{
ClrDin; //Send zero to SDO pin
}
delay(10);
SetSclk;
delay(10);
ValueToWrite <<= 1; //Rotate data
}
}
SetCs;
}
//---------------------------------
//void ReadFromAD7190(unsigned char count,unsigned char *buf)
//---------------------------------
//Function that reads from the AD7190 via the SPI port.
//--------------------------------------------------------------------------------
void ReadFromAD7190(unsigned char count, unsigned char *buf)
{
unsigned char i = 0;
unsigned char j = 0;
unsigned int iTemp = 0;
unsigned char RotateData = 0;
SetSclk;
delay(2);
SetCs;
delay(2);
ClrCs;
delay(3);
for(j=count; j>0; j--)
{
for(i=0; i<8; i++)
{
ClrSclk;
RotateData <<= 1; //Rotate data
delay(10);
iTemp = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14); //Read SDI of AD7190
SetSclk;
if(iTemp)
{
RotateData |= 1;
}
delay(10);
}
*(buf + j - 1)= RotateData;
}
SetCs;
}
int mian()
{
buf[0] = 0xff;
WriteToAD7190(1,buf); //复位AD7190
WriteToAD7190(1,buf);
WriteToAD7190(1,buf);
WriteToAD7190(1,buf);
WriteToAD7190(1,buf);
delay(1000);
while(1)
{
buf[2] = 0x08;
buf[1] = 0x03;
buf[0] = 0xFF;
WriteToAD7190(3,buf); //write mode register,internal 4.92MHz clock,output data rate=4.7Hz
buf[0] = 0x60; //读ID
WriteToAD7190(1,buf);
temp=GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14); //在这里发现AD7190的数据输出脚一直为高,导致不能进行读
while(temp);
ReadFromAD7190(1,buf);
}
}
|