Hi, expert
My customer is using DAC8760 pin to pin replace AD5421, but they found no data from DAC output.
They can write into the register to adjust the output current, but when they read the DAC data, the SDO is always low. (LATCH/SCK/SDIN signals are correct)
Attached their code, could you please help analysis this problem? Thanks
Best Regards.
Chen
static unsigned char buf[3] = {0,0,0}; static unsigned char buf2[3] = {0,0,0}; statc Modechange=1; static SetAoValue=0xD554;//20MA static ReadFromAoStatus=0; static ReadFromAoData=0; static ReadFromAoCtrl=0; //the function write data to the ADC's register (DAC) void WriteToADC(unsigned char count,unsigned char *buf) { unsigned char ValueToWrite = 0; unsigned char i = 0; unsigned char j = 0; //set latch low GPIOPinWrite(DAC_LATCH_PORT, DAC_LATCH_PIN, ~DAC_LATCH_PIN); for ( i=count; i>0; i-- ) { ValueToWrite = *(buf+i-1); for (j=0; j<8; j++) { GPIOPinWrite(DAC_SCK_PORT, DAC_SCK_PIN,~DAC_SCK_PIN); if(0x80 == (ValueToWrite & 0x80)) { GPIOPinWrite(DAC_SDI_PORT, DAC_SDI_PIN,DAC_SDI_PIN); //Send one to SDIN pin of AD5422 } else { GPIOPinWrite(DAC_SDI_PORT, DAC_SDI_PIN,~DAC_SDI_PIN); //Send zero to SDIN pin of AD5422 } SysDelayUs(1); GPIOPinWrite(DAC_SCK_PORT, DAC_SCK_PIN,DAC_SCK_PIN); SysDelayUs(1); ValueToWrite <<= 1; //Rotate data } } GPIOPinWrite(DAC_SCK_PORT, DAC_SCK_PIN,~DAC_SCK_PIN); SysDelayUs(1); GPIOPinWrite(DAC_LATCH_PORT, DAC_LATCH_PIN, DAC_LATCH_PIN); // SysDelayUs(20); SysDelayUs(10); } //the function read the data register from DAC void ReadFromADC(unsigned char count,unsigned char *buf) { unsigned char i = 0; unsigned char j = 0; unsigned char iTemp = 0; unsigned char RotateData = 0; GPIOPinWrite(DAC_LATCH_PORT, DAC_LATCH_PIN, ~DAC_LATCH_PIN); for(j=count; j>0; j--) { for(i=0; i<8; i++) { GPIOPinWrite(DAC_SCK_PORT, DAC_SCK_PIN,~DAC_SCK_PIN); RotateData <<= 1; //Rotate data SysDelayUs(1); GPIOPinWrite(DAC_SDI_PORT, DAC_SDI_PIN,~DAC_SDI_PIN); //Write a nop condition when read the data. iTemp = GPIOPinRead(DAC_SDO_PORT,DAC_SDO_PIN); //Read SDO of AD5422 GPIOPinWrite(DAC_SCK_PORT, DAC_SCK_PIN,DAC_SCK_PIN); if(iTemp == 1) { RotateData |= 1; } SysDelayUs(1); } *(buf+j-1)= RotateData; } GPIOPinWrite(DAC_SCK_PORT, DAC_SCK_PIN,~DAC_SCK_PIN); SysDelayUs(1); GPIOPinWrite(DAC_LATCH_PORT, DAC_LATCH_PIN, DAC_LATCH_PIN); // SysDelayUs(20); SysDelayUs(10); } void DacDemo(void) { //IO���ų�ʼ����ʹ��GPIOģ��SPI //set control //�趨0-24MA��� if(Modechange) { Modechange=0; buf[0]=0x07;//0-24ma buf[2]=0x55; buf[1]=0x10; WriteToADC(3,buf);//�趨״̬ SysDelayUs(100); } //ͨ�������趨 buf[2] = 0x01; //Data register buf[1] = (SetAoValue>>8)&0xff; buf[0] = SetAoValue&0xff; WriteToADC(3,buf);// SysDelayUs(100); //ͨ��״̬�ز� buf[2] = 0x02;//READ buf[1] = 0x00; buf[0] = 0x00;//STATUS WriteToADC(3,buf); ReadFromADC(3,buf2); ReadFromAoStatus=buf2[1]; ReadFromAoStatus<<=8; ReadFromAoStatus+=buf2[0]; SysDelayUs(100); //ͨ�����ݻز� buf[2] = 0x02;//READ buf[1] = 0x00; buf[0] = 0x01;//DATA WriteToADC(3,buf); ReadFromADC(3,buf2); ReadFromAoData=buf2[1]; ReadFromAoData<<=8; ReadFromAoData+=buf2[0]; SysDelayUs(100); //ͨ�����ƻز� buf[2] = 0x02;//READ buf[1] = 0x00; buf[0] = 0x02;//control WriteToADC(3,buf); ReadFromADC(3,buf2); ReadFromAoCtrl=buf2[1]; ReadFromAoCtrl<<=8; ReadFromAoCtrl+=buf2[0]; SysDelayUs(100); }