大学生
最后登录1970-1-1
在线时间 小时
注册时间2017-6-24
|
10火花
有没有大佬用STM32驱动过AD7888,读数一直为0
unsigned int ReadFromAD7888ViaSPI(unsigned char RegValue)
{
unsigned int ReceiveData = 0;
unsigned char ControlValue = 0;
unsigned int i = 0;
unsigned int iTemp =0;
ControlValue = RegValue;
//Write Control register and Read result data
GPIO_ResetBits(CS_GPIO_PORT, CS_GPIO_PIN); //CS=0
GPIO_ResetBits(SCLK_GPIO_PORT, SCLK_GPIO_PIN); //SCLK=0
for(i=0; i<16; i++)
{
ReceiveData <<= 1; //Rotate data
//write register code
if(i < 8)
{
if(0x80 == (ControlValue & 0x80)) //1000 0000
{
GPIO_SetBits(DIN_GPIO_PORT, DIN_GPIO_PIN);// DIN=1
}
else
{
GPIO_ResetBits(DIN_GPIO_PORT, DIN_GPIO_PIN);//DIN=0
}
ControlValue <<= 1; //Rotate data
}
Delay(1);
GPIO_SetBits(SCLK_GPIO_PORT, SCLK_GPIO_PIN); //SCLK=1
//read data code
iTemp = GPIO_ReadInputDataBit(DOUT_GPIO_PORT, DOUT_GPIO_PIN); //Read SDI of AD7888
if(0x00000020 == (iTemp & 0x00000020)) //DOUT=1
{
ReceiveData |= 1;
}
Delay(1);
GPIO_ResetBits(SCLK_GPIO_PORT, SCLK_GPIO_PIN); //SCLK=0
}
GPIO_SetBits(CS_GPIO_PORT, CS_GPIO_PIN); //CS=1
return ReceiveData;
}
|
|