//SPI example using AD7303 DAC from Analog Devices //set DAC for simultaneous update of two channels // Mega644 GCC // //connect MOSI B.5 to DIN on AD7303 //connect SCLK B.7 to SCLK on AD7303 //connect B.4 to notSYNC on the AD7303 #include #include #include #define begin { #define end } // bit handling macros for i/o registers #define READ(U, N) ((U) >> (N) & 1u) #define SET(U, N) ((void)((U) |= 1u << (N))) #define CLR(U, N) ((void)((U) &= ~(1u << (N)))) #define FLIP(U, N) ((void)((U) ^= 1u << (N))) // AD7303 control words uint8_t DAC_cntl_1, DAC_cntl_2; // DDS accumulator and increment uint8_t DDSacc, DDSinc; // throwaway variable // not used since DAC does not return any data uint8_t junk ; int main(void) begin DDSinc = 16; //sawtooth DDS rate //set up i/o data direction //DDRB.4 = 1; //output chip select for DAC (notSYNC) //DDRB.5 = 1; //output MOSI //DDRB.6 = 0; //input MISO is not used by the DAC //DDRB.7 = 1; //output SCLK DDRB = (1<