Looking at the ADC and DAC devices

This is for an Analog Devices Sharc processor

Both the analogue digital converter (ADC) and the digital analogue converter (DAC) have to be configured for correct operation. That is the sample rate, sample size, type of sampling format, master/slave operation etc....

Using the SPI port

Both the ADC and DAC are configured after the reading of the configuration from the switches but before the core loop is run. here we show a suitable coding for the ADC communication via SPI.

            
unsigned int 	adc_setup[3]={0x00000100,0x00001000,0x00002000};
//	Add on ADC gain factor to [0]
	adc_setup[0] |= adc_gain;
//	Writing to SPI for the AD1871
	*(int*)IISTX=(int)adc_setup;
	*(int*)IMSTX=1;
	*(int*)CSTX=3;
	*(int*)SPICTL=0;	// clear control
	*(int*)SPICTL|=SPIEN|SPI_MS|PSSE|BAUDR4|WL16|FLS0|NSMLS|DCPH0|DF|CPHASE;
	for(i=0;i &lt 30;i++)asm("nop;");
	*(int*)SPICTL|=TDMAEN;
//  Clear control
	for(i=0;i &lt 4096; i++)asm("nop;"); *(int*)spictl=0; 

            

The ADC parameters are held in the array adc_setup. The basic parameters are modified by the gain setting just calculated from reading the switch settings. There are 3 x 16bit words to be sent to the ADC1871.

The SPI port is pointed to the data, set into master mode, word size, number of words etc placed. Then the data sent. Two pauses are needed for correct transmission, one on completion of SPI port set and one after the transmission. Note: a GPIO port needs to be set in order to flag the ADC1871 as selected for slave entry of data.

The DAC is done in a similar way with the DAC selected for slave data entry.