This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

请教DAC8571问题,

Other Parts Discussed in Thread: DAC8571

正在调DAC8571,按如图的连接做的小模块,采用模拟I2C的方式。不管发送的是多少,输出都有几到几十毫伏(应该是噪声)。读出的都是32767。还没找出是什么原因,希望有人帮忙看看错误出在哪里了。在此先谢过了。

模拟IIC的代码

//***************************IIC.c*********************************************

 

//产生IIC起始信号
void IIC_Start(void)
{
	
	SDA_OUT();     
	IIC_SDA=1;	  	  
	IIC_SCL=1;
	delay_us(4);
 	IIC_SDA=0;//START:when CLK is high,DATA change form high to low 
	delay_us(4);
	IIC_SCL=0;
	

}	  
//产生IIC终止信号
void IIC_Stop(void)
{
	SDA_OUT();
	IIC_SCL=0;
	IIC_SDA=0;//STOP:when CLK is high DATA change form low to high
 	delay_us(4);
	IIC_SCL=1; 
	IIC_SDA=1;/
	delay_us(4);							   	
}
 
u8 IIC_Wait_Ack(void)
{
	u8 ucErrTime=0;
	 
	IIC_SDA=1;delay_us(1);	   
	IIC_SCL=1;delay_us(1);	
	SDA_IN();      
	while(READ_SDA)
	{
		ucErrTime++;
		if(ucErrTime>250)
		{
			IIC_Stop();
			return 1;
		}
	}
	IIC_SCL=0;   
	return 0;  
} 
 
void IIC_Ack(void)
{
	IIC_SCL=0;
	SDA_OUT();
	IIC_SDA=0;
	delay_us(2);
	IIC_SCL=1;
	delay_us(2);
	IIC_SCL=0;
}
	    
void IIC_NAck(void)
{
	IIC_SCL=0;
	SDA_OUT();
	IIC_SDA=1;
	delay_us(2);
	IIC_SCL=1;
	delay_us(2);
	IIC_SCL=0;
}					 				     
	  
void IIC_Send_Byte(u8 txd)
{                        
    u8 t;   
	SDA_OUT(); 	    
    IIC_SCL=0;
    for(t=0;t<8;t++)
    {              
        IIC_SDA=(txd&0x80)>>7;
        txd<<=1; 	  
		delay_us(2);  		
		IIC_SCL=1;
		delay_us(2); 
		IIC_SCL=0;	
		delay_us(2);
    }	 
} 	    
u8 IIC_Read_Byte(unsigned char ack)
{
	unsigned char i,receive=0;
	SDA_IN();
    for(i=0;i<8;i++ )
	{
        IIC_SCL=0; 
        delay_us(2);
		IIC_SCL=1;
        receive<<=1;
        if(READ_SDA)receive++;   
		delay_us(1); 
    }					 
    if (!ack)
        IIC_NAck();
    else
        IIC_Ack(); 
    return receive;
}

//************************************IIC  end***************************************************
//***********************************DAC.c*****************************************

void DAC8571_Init(void)
{
	IIC_Init();
}

void DAC8571_Write(void)
{
	
	IIC_Start();
	
	IIC_Send_Byte(0x98);
	IIC_Wait_Ack();
	IIC_Send_Byte(0x10);
	IIC_Wait_Ack();
	IIC_Send_Byte(0xff);
	IIC_Wait_Ack();
	IIC_Send_Byte(0xff);
	IIC_Wait_Ack();
	IIC_Stop();
	
}

unsigned int DAC8571_Read(void)
{
	unsigned int temp1,temp2;
	IIC_Start();
	IIC_Send_Byte(0x99);
	IIC_Wait_Ack();

	temp1 = IIC_Read_Byte(1);
//	temp1 <<= 8; 
	temp2 = IIC_Read_Byte(1);
	temp1 = temp1*256+temp2;
	IIC_Send_Byte(0x20);
	IIC_NAck();
	IIC_Stop();
	return temp1;
}

//******************************DAC.c  end********************************