已回答假定已回答

求问AD9913写控制字程序。程序如下,输出不了信号,求指正程序错误

wangjianfree 在 2016-5-3 詢問的問題
最後回覆由su yongchao於2016-11-14提供

void WriteToAD9910ViaSpi(unsigned char RegisterAddress, unsigned char NumberofRegisters, unsigned int *RegisterData)

{

  unsigned char ControlValue = 0;

  unsigned int ValueToWrite = 0;

  signed char RegisterIndex = 0;

  unsigned char i = 0;

 

 

  //Create the 8-bit header

  ControlValue = RegisterAddress;

 

 

 

 

  ad9913_cs_1;

  delay_us(2);

  ad9913_cs_0; //bring CS low

  delay_us(2);

  ad9913_sclk_1;

  delay_us(2);

 

 

  ad9913_sdio; //Make SDIO an output

  delay_us(2);

  //Write out the control word

  for(i=0; i<8; i++)

  {

  ad9913_sclk_0;

  if(0x80 == (ControlValue & 0x80))

  {

  ad9913_sdio_1;  //Send one to SDIO pin

  }

  else

  {

  ad9913_sdio_0;  //Send zero to SDIO pin

  }

  delay_us(2);

  ad9913_sclk_1;

  delay_us(2);

  ControlValue <<= 1; //Rotate data

  }

  delay_us(20);

  //And then the data

  for (RegisterIndex=NumberofRegisters; RegisterIndex>0; RegisterIndex--)

  {

  ValueToWrite = *(RegisterData + RegisterIndex - 1);

  for (i=0; i<32; i++)

  {

  ad9913_sclk_0;

  if(0x80000000 == (ValueToWrite & 0x80000000))

  {

  ad9913_sdio_1;  //Send one to SDIO pin

  }

  else

  {

  ad9913_sdio_0;  //Send zero to SDIO pin

  }

  delay_us(2);

  ad9913_sclk_1;

  delay_us(2);

  ValueToWrite <<= 1; //Rotate data

  }

  }

  delay_us(2);

  ad9913_cs_1; //bring CS high again

  //IO_Update();

  ad9913_updata;

  ad9913_updata_0;

  delay_us(5);

  ad9913_updata_1;

  delay_us(20);

  ad9913_updata_0;

}

結果