AnsweredAssumed Answered

ADuC845 communicating with AD5666

Question asked by jwanja on Apr 23, 2012
Latest reply on Apr 23, 2012 by jwanja

I am trying to use an external DAC connected to the ADuC845. While I could use the SPI on the microcontroller to write information and update the DAC, I am already using Timer2 as an external input counter. I have written my own transfer function to the DAC that works nearly identical to the way SPI would function, but when I run the program nothing changes at the DACs output (output should begin to output 2.5 [V] from DAC A using the attached program). All DAC outputs are idling around 600 [mV]. I made sure to transfer from MSB to LSB and made sure all timing considerations were taken account of. Could anyone offer insights to what might be happening? Ill attach my code and a picture of my timing diagram.

 

#include <ADuC845.h>
#include <math.h>


int count = 0;
char txComplete = 0;


void transferByte(char byte)
{
          int i = 0;
          int j = 0;
          for(i=7;i>=0;i--)
          {
                    for (j=0; j<50; j++) {}
                    P2 ^= 0x01;
                    if( (byte >> i) & 0x01 )
                              P2 |= 0x02;
                    else P2 &= ~0x02;
                    for (j=0; j<50; j++) {}
                    P2 ^= 0x01; 
          }
}


main ()
{ 
          char byte = 0;
          int i=0;
          int j=0;

      //Allow all devices 1second to fully power on
          while(j<6)
          { 
                    for(i=0;i<30000;i++) {}
                    j++;
          }

      // I know I am using Port 2 for my timer port, but this is a simple test program with no timer functions. 
      //       I will change Port numbers when I put into my final program
      // P2.0 ==> SCLK to DAC
      // P2.1 ==> DIN to DAC
      // P2.3 ==> SYNC to DAC
          P2 = 0x01; 


          //Pulse pin P2.3 to notify external DAC of transfer begin pulsing SCLK
          P2 ^= 0x08;
          for(i = 0; i <  50; i++) {}
         P2 ^=0x01;
          P2 ^= 0x08;


          //Transfer first of 4 bytes to external DAC
          //          1st byte - 4 dont cares then 4 bit control - 0bXXXX0011
          //          control 0011 - write to and update DAC output 'N'
          byte = 0x03;
          transferByte(byte);
  
          //2nd byte - 4 bit address 'N' then 4 MSBs of data
          //          address - 0000 = 0x0 = DAC A
          //          Test of 2.5V - 0x8000 
          byte = 0x08;
          transferByte(byte);
  
          //3rd byte - next 8 bits of data
          byte = 0x00;
          transferByte(byte);
  
          //4th byte - final 4 bits of data and 4 dont cares
          byte = 0x00;
          transferByte(byte);
  
          while(1)
          {
  
          }
}

 

Screen Shot 2012-04-23 at 2.24.12 PM.png

Attachments

Outcomes