Hi,
After i write the data, DAC80004 is no output in the board.
SPI communication and readback are OK.
What is the problem? Could anyone help to check the code or give some suggestion? Thanks.
The Timing waveform is as below.
#include "hardware.h"
unsigned long Dac_Write_Read(unsigned long CMD);
unsigned int dac_states;
void Dac8004_Init()
{
Dac_Write_Read(0x0800000f);//enable sdo register
Dac_Write_Read(0x04f0000f);//power on
Dac_Write_Read(0x06f0000f);//update control by the 32 falling edge of sck
Dac_Write_Read(0x1d000000);
Dac_Write_Read(0x05000002);
dac_states=Dac_Read();
}
void Write_Update_Dac(unsigned int channel,unsigned int data)
{
unsigned long cmd,i;
i=0;
//GPIO_SetBits(GPIOB, GPIO_Pin_11);
cmd=(((unsigned long)channel)<<20);
cmd=0x03000000|cmd;
cmd=cmd|((unsigned long)data<<4);
Dac_Write_Read(cmd);
GPIO_ResetBits(GPIOB, GPIO_Pin_11);
GPIO_ResetBits(GPIOB, GPIO_Pin_2);
//while(i++<40);
GPIO_SetBits(GPIOB, GPIO_Pin_11);
GPIO_SetBits(GPIOB, GPIO_Pin_2);
}
unsigned long Dac_Read()
{
return Dac_Write_Read(0x0e000000);
}
unsigned long Dac_Write_Read(unsigned long CMD)//27fc
{
unsigned long data_in;
unsigned short CMD_H,CMD_L;
unsigned long r;
CMD_H=CMD>>16;
CMD_L=CMD&0x0000ffff;
GPIO_ResetBits(GPIOA, GPIO_Pin_4);
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData16( SPI1, CMD_H);
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
CMD_H=SPI_I2S_ReceiveData16(SPI1);
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData16( SPI1, CMD_L);
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
CMD_L= SPI_I2S_ReceiveData16(SPI1);
r=CMD_H;
r=(r<<16)|CMD_L;
GPIO_SetBits(GPIOA, GPIO_Pin_4);
return r;
}