Post Go back to editing

数模芯片AD5383使用中遇到的问题

ADI工程师:

    您好!最近购买了你们数模芯片AD5383和其他别的芯片(共计几千元,用于新项目的研发中),在使用AD5383中,数据无法更新,发现LOAD引脚上电就是高电平,那我还怎么把它置低写入数据呢,我使用的是SPI通信,目前卡在这个地方了,数据无法加载到输出引脚,很是苦恼,还希望你们能够提供技术支持 ,谢谢了!

    可以读芯片寄存器中的数据(已实现)!

//IO操作函数 

#define SPI_SYNC    PEout(0) //SYNC

#define SPI_SCLK  PEout(1) //SCLK

#define SPI_DIN  PEout(2) //DIN

#define SPI_SDA   PEin(3)  //输入SDA

#define SPI_LDAC   PFout(0)  //LDAC

AD5383程序如下:

/********************************************************************************
Function that writes to the AD5380 via the SPI port.
********************************************************************************/


void WriteToAD5380ViaSpi(int32_t RegisterData)
{

long int ValueToWrite = RegisterData;
int i;

// SPI start

SPI_SYNC=1;
delay_us(1);
SPI_SYNC=0;  //bring SYNC low
delay_us(1);

//Write out the ControlWord

for(i=0; i<24; i++)
{
  SPI_SCLK=1;
  delay_us(1);
  if(0x800000 == (ValueToWrite & 0x800000))
  {
   SPI_DIN=1;   //Send one to DIN pin
  }
  else
  {
   SPI_DIN=0;   //Send zero to DIN pin
  }
  delay_us(1);
  SPI_SCLK=0;
  delay_us(1);
  ValueToWrite <<= 1; //Rotate data
  delay_us(1);

}
 

    // SPI ends


SPI_SYNC=1;
   delay_us(5);

}


/********************************************************************************
Function that read from the AD5380 via the SPI port.
********************************************************************************/


void ReadFromAD5380ViaSpi(int32_t *RegisterData)
{


unsigned int     i = 0;
unsigned int   iTemp = 0;
unsigned long   RotateData = 0;

unsigned long   Noop = NOP;

// SPI start

SPI_SYNC=1;
delay_us(1);
SPI_SYNC=0;  //bring SYNC low
delay_us(1);

for(i=0; i<24; i++)
{
  SPI_SCLK=1;
  delay_us(1);
//////////////////////////////////////////////////
if(0x800000 == (Noop & 0x800000))
  {
   SPI_DIN=1;   //Send one to SDI pin
  }
  else
  {
   SPI_DIN=0;   //Send zero to SDI pin
  }
//////////////////////////////////////////////////

  SPI_SCLK=0;
  delay_us(1);
   
  iTemp = SPI_SDA;   //Read DIN of AD5383, PE3
  RotateData <<= 1;
 
  if(iTemp==0X01 )
  {

   RotateData |= 1;
  
  }
 
  Noop <<= 1;
      delay_us(5);
}

 
      
    // SPI ends

SPI_SYNC=1;

    delay_us(2);
*RegisterData=RotateData;

}


void ComPortsToPC(int32_t buf)
{
unsigned char tx[3] = {0,0,0};
  u8 t;
    tx[2] = ((buf)&0xFF0000)>>16;
    tx[1] = ((buf)&0x00FF00)>>8;
    tx[0] = (buf)&0x000000FF;
   for(t=0;t<3;t++)
   {
    USART_SendData(USART1, tx[t]);         //向串口1发送数据
    while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
   }
  
 
}

主程序如下:

main()

{

AD5383_Init();

SPI_LDAC=1;

delay_us(1);

//-------------------------------------------------------------------------------------

//Enable monitor and internal REF to 1.25v and select power down mode that is 100k_GND

//-------------------------------------------------------------------------------------

cstr = Write | Special_Function_Register | Control_Register  |Internal_REF_Enabled | Internal_REF_1_25 | PowerDown_100K_toGND| toggle_0_7;

WriteToAD5380ViaSpi(cstr);

delay_us(1);

cstr = Write | Input_Data_Register | Channel_Vout0   |0x000FFF;  //Vout3 IS 0.6V
WriteToAD5380ViaSpi(cstr);
delay_us(1);

cstr = Write | Input_Data_Register | Channel_Vout1   | 0x000FFF;  //Vout3 IS 0.6V
WriteToAD5380ViaSpi(cstr);
delay_us(1);

cstr = Write | Input_Data_Register | Channel_Vout2   | 0x000FFF;  //Vout3 IS 0.6V
WriteToAD5380ViaSpi(cstr);
delay_us(1);

  cstr = Write | Input_Data_Register | Channel_Vout3   | 0x000FFF;  //Vout3 IS 0.6V
WriteToAD5380ViaSpi(cstr);
delay_us(1);

cstr = Write | Input_Data_Register | Channel_Vout4   | 0x002000;  //Vout3 IS 1.2V
WriteToAD5380ViaSpi(cstr);
delay_us(1);

cstr = Write | Input_Data_Register | Channel_Vout5   | 0x000FFF;  //Vout3 IS 1.2V
WriteToAD5380ViaSpi(cstr);
delay_us(1);

cstr = Write | Input_Data_Register | Channel_Vout6   | 0x003FFF;  //Vout3 IS 2.4V
WriteToAD5380ViaSpi(cstr);
delay_us(1);

cstr = Write | Input_Data_Register | Channel_Vout7   | 0x000FFF;  //Vout3 IS 2.4V
WriteToAD5380ViaSpi(cstr);
delay_us(1);


SPI_LDAC=0;
  delay_us(1);
//delay(2);
SPI_LDAC=1;
delay_us(1);
//delay(2);

while(1)

{

  LED0=!LED0;   //闪烁LED,提示系统正在运行.

  LED1=!LED1;   //闪烁LED,提示系统正在运行.

  delay_ms(500);

cstr = Read | Special_Function_Register | Control_Register; // readback control register data

   WriteToAD5380ViaSpi(cstr);                    

   ReadFromAD5380ViaSpi(&buf);   //Read select register, using two instruction cycles

  ComPortsToPC(buf);

}

}

Reply

//IO操作函数 

#define SPI_SYNC    PEout(0) //SYNC

#define SPI_SCLK  PEout(1) //SCLK

#define SPI_DIN  PEout(2) //DIN

#define SPI_SDA   PEin(3)  //输入SDA

#define SPI_LDAC   PFout(0)  //LDAC

AD5383程序如下:

/********************************************************************************
Function that writes to the AD5380 via the SPI port.
********************************************************************************/


void WriteToAD5380ViaSpi(int32_t RegisterData)
{

long int ValueToWrite = RegisterData;
int i;

// SPI start

SPI_SYNC=1;
delay_us(1);
SPI_SYNC=0;  //bring SYNC low
delay_us(1);

//Write out the ControlWord

for(i=0; i<24; i++)
{
  SPI_SCLK=1;
  delay_us(1);
  if(0x800000 == (ValueToWrite & 0x800000))
  {
   SPI_DIN=1;   //Send one to DIN pin
  }
  else
  {
   SPI_DIN=0;   //Send zero to DIN pin
  }
  delay_us(1);
  SPI_SCLK=0;
  delay_us(1);
  ValueToWrite <<= 1; //Rotate data
  delay_us(1);

}
 

    // SPI ends


SPI_SYNC=1;
   delay_us(5);

}


/********************************************************************************
Function that read from the AD5380 via the SPI port.
********************************************************************************/


void ReadFromAD5380ViaSpi(int32_t *RegisterData)
{


unsigned int     i = 0;
unsigned int   iTemp = 0;
unsigned long   RotateData = 0;

unsigned long   Noop = NOP;

// SPI start

SPI_SYNC=1;
delay_us(1);
SPI_SYNC=0;  //bring SYNC low
delay_us(1);

for(i=0; i<24; i++)
{
  SPI_SCLK=1;
  delay_us(1);
//////////////////////////////////////////////////
if(0x800000 == (Noop & 0x800000))
  {
   SPI_DIN=1;   //Send one to SDI pin
  }
  else
  {
   SPI_DIN=0;   //Send zero to SDI pin
  }
//////////////////////////////////////////////////

  SPI_SCLK=0;
  delay_us(1);
   
  iTemp = SPI_SDA;   //Read DIN of AD5383, PE3
  RotateData <<= 1;
 
  if(iTemp==0X01 )
  {

   RotateData |= 1;
  
  }
 
  Noop <<= 1;
      delay_us(5);
}

 
      
    // SPI ends

SPI_SYNC=1;

    delay_us(2);
*RegisterData=RotateData;

}


void ComPortsToPC(int32_t buf)
{
unsigned char tx[3] = {0,0,0};
  u8 t;
    tx[2] = ((buf)&0xFF0000)>>16;
    tx[1] = ((buf)&0x00FF00)>>8;
    tx[0] = (buf)&0x000000FF;
   for(t=0;t<3;t++)
   {
    USART_SendData(USART1, tx[t]);         //向串口1发送数据
    while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
   }
  
 
}

主程序如下:

main()

{

AD5383_Init();

SPI_LDAC=1;

delay_us(1);

//-------------------------------------------------------------------------------------

//Enable monitor and internal REF to 1.25v and select power down mode that is 100k_GND

//-------------------------------------------------------------------------------------

cstr = Write | Special_Function_Register | Control_Register  |Internal_REF_Enabled | Internal_REF_1_25 | PowerDown_100K_toGND| toggle_0_7;

WriteToAD5380ViaSpi(cstr);

delay_us(1);

cstr = Write | Input_Data_Register | Channel_Vout0   |0x000FFF;  //Vout3 IS 0.6V
WriteToAD5380ViaSpi(cstr);
delay_us(1);

cstr = Write | Input_Data_Register | Channel_Vout1   | 0x000FFF;  //Vout3 IS 0.6V
WriteToAD5380ViaSpi(cstr);
delay_us(1);

cstr = Write | Input_Data_Register | Channel_Vout2   | 0x000FFF;  //Vout3 IS 0.6V
WriteToAD5380ViaSpi(cstr);
delay_us(1);

  cstr = Write | Input_Data_Register | Channel_Vout3   | 0x000FFF;  //Vout3 IS 0.6V
WriteToAD5380ViaSpi(cstr);
delay_us(1);

cstr = Write | Input_Data_Register | Channel_Vout4   | 0x002000;  //Vout3 IS 1.2V
WriteToAD5380ViaSpi(cstr);
delay_us(1);

cstr = Write | Input_Data_Register | Channel_Vout5   | 0x000FFF;  //Vout3 IS 1.2V
WriteToAD5380ViaSpi(cstr);
delay_us(1);

cstr = Write | Input_Data_Register | Channel_Vout6   | 0x003FFF;  //Vout3 IS 2.4V
WriteToAD5380ViaSpi(cstr);
delay_us(1);

cstr = Write | Input_Data_Register | Channel_Vout7   | 0x000FFF;  //Vout3 IS 2.4V
WriteToAD5380ViaSpi(cstr);
delay_us(1);


SPI_LDAC=0;
  delay_us(1);
//delay(2);
SPI_LDAC=1;
delay_us(1);
//delay(2);

while(1)

{

  LED0=!LED0;   //闪烁LED,提示系统正在运行.

  LED1=!LED1;   //闪烁LED,提示系统正在运行.

  delay_ms(500);

cstr = Read | Special_Function_Register | Control_Register; // readback control register data

   WriteToAD5380ViaSpi(cstr);                    

   ReadFromAD5380ViaSpi(&buf);   //Read select register, using two instruction cycles

  ComPortsToPC(buf);

}

}

Children
No Data