ADIS16209使用STM32内部SPI通信读不出数据

程序如下:使用STM32 HAL库

uint8_t SPI_ADIS16209_Sendbyte(uint8_t byte)
{
uint8_t d_read,d_send = byte;
if(HAL_SPI_TransmitReceive(&hspi1,&d_send,&d_read,1,1000)!=HAL_OK)
d_read = Dummy_Byte;
return d_read;
}

uint8_t Read_ADIS16209_Data(uint8_t Dst,uint8_t *RcvBuf)
{
uint8_t i = 0;

CLR_CS();
__nop();__nop();__nop();__nop();
SPI_ADIS16209_Sendbyte(Dst&0x3f);
SPI_ADIS16209_Sendbyte(0X00);
SET_CS();
for(i=1;i>0;i--);
CLR_CS();
for(i=0;i<2;i++)
{
RcvBuf[i] = SPI_ADIS16209_Sendbyte(0x00);
}
SET_CS();
for(i=1;i>0;i--);
return 1;
}

int main(void)
{

HAL_Init();


SystemClock_Config();

MX_GPIO_Init();
MX_SPI1_Init();
__HAL_SPI_ENABLE(&hspi1);

while (1)
{

Read_ADIS16209_Data(XINCL_OUT,XINCL_OUT_DATA);
HAL_Delay(10);
Read_ADIS16209_Data(YINCL_OUT,YINCL_OUT_DATA);
HAL_Delay(10);
Read_ADIS16209_Data(ROT_OUT,ROT_OUT_DATA);
HAL_Delay(10);
}

}

以下是模拟SPI通信程序:

void WriteToADIS16209ViaSpi(unsigned char RegisterAddress, unsigned char NumberofRegisters, unsigned char *RegisterData)
{
unsigned char ControlValue = 0;
unsigned int ValueToWrite = 0;
unsigned char RegisterIndex = 0;
unsigned char i = 0;

for(RegisterIndex=0; RegisterIndex<NumberofRegisters*2; RegisterIndex++)//every register of ADIS16209 takes up two bytes
{
//Create the 8-bit header
ControlValue = (RegisterAddress + RegisterIndex) | 0x80;
SET_SCL();
Delay(1);
SET_CS();
Delay(1);
CLR_CS();
Delay(1);
//Write out the control word
for(i=0; i<8; i++)
{
CLR_SCL();
if(0x80 == (ControlValue & 0x80))
{
SET_SDO(); //Send one to DIN pin of ADIS16209
}
else
{
CLR_SDO(); //Send zero to DIN pin of ADIS16209
}
Delay(1);
SET_SCL();
Delay(1);
ControlValue <<= 1; //Rotate data
}
//And then the data
ValueToWrite = *(RegisterData + RegisterIndex);
for (i=0; i<8; i++)
{
CLR_SCL();
if(0x80 == (ValueToWrite & 0x80))
{
SET_SDO(); //Send one to DIN pin of ADIS16209
}
else
{
CLR_SDO(); //Send zero to DIN pin of ADIS16209
}
Delay(1);
SET_SCL();
Delay(1);
ValueToWrite <<= 1; //Rotate data
}
SET_CS(); //bring CS high again
Delay(2);
}
}

uint16_t ReadFromADIS16209ViaSpi(unsigned char RegisterAddress, unsigned char NumberofRegisters, unsigned char *RegisterData)
{
unsigned char ControlValue = 0;
unsigned char RegisterIndex = 0;
unsigned char ReceiveData = 0;
unsigned char i = 0, j = 0;
//unsigned int iTemp = 0;

for(RegisterIndex=0; RegisterIndex<NumberofRegisters; RegisterIndex++)
{
for(j=0;j<2;j++) //Repeat reading to make sure the data on DOUT is just the register which you are going to read
{
//Create the 8-bit header
ControlValue = RegisterAddress + RegisterIndex*2;//every register of ADIS16209 takes up two bytes
SET_SCL();
Delay(1);
SET_CS();
Delay(1);
CLR_CS(); //bring CS low
Delay(1);

//Write out the control word
for(i=0; i<8; i++)
{
CLR_SCL();
if(0x80 == (ControlValue & 0x80))
{
SET_SDO(); //Send one to DIN pin of ADIS16209
}
else
{
CLR_SDO(); //Send zero to DIN pin of ADIS16209
}
Delay(1);
SET_SCL();
ReceiveData <<= 1; //Rotate data

if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_6)==GPIO_PIN_SET)
{
ReceiveData |= 1;
}
Delay(1);
ControlValue <<= 1; //Rotate data
}
//*(RegisterData + RegisterIndex*2 + 1) = ReceiveData;
//Read data in
for(i=0; i<8; i++)
{
CLR_SCL();
Delay(1);
SET_SCL();
ReceiveData <<= 1; //Rotate data


if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_6)==GPIO_PIN_SET)
{
ReceiveData |= 1;
}
Delay(1);
}
//*(RegisterData + RegisterIndex*2) = ReceiveData;
SET_CS(); //bring CS high again
Delay(2);
}
}
return ReceiveData;
}

int main()

{

//其他省略

RegisterData[0] = 0x01;
RegisterData[1] = 0x23;
RegisterData[2] = 0x05;
RegisterData[3] = 0xA6;

WriteToADIS16209ViaSpi(SUPPLY_OUT,2,RegisterData);

RegisterData[0] = 0x88;
RegisterData[1] = 0x88;
RegisterData[2] = 0x88;
RegisterData[3] = 0x88;

aa = ReadFromADIS16209ViaSpi(SUPPLY_OUT,2,RegisterData);

}

ADIS16209读取数据前 是否要先发送2个字节的地址,然后在读吗?