You are currently viewing How to Interface SPI DAC with TMS320C6745 DSP

How to Interface SPI DAC with TMS320C6745 DSP

Spread the love

The TMS320C6745 DSP Development Board is specially designed for developers in dsp field as well as beginners. The kit is designed in such way that all the possible features of the DSP will be easily used by everyone.

The kit supports in Code Composer Studio3.3 and later, with XDS100 v1 USB Emulator which is done USB port.


Digital-to-Analog converter (abbreviated DAC, D/A or D to A) is a device that converts a digital value to a continuous analog signal representation. The DAC may also provide an isolated measurement. The reverse operation is performed by an analog to digital converter (ADC).

Typically, a DAC is an electronic device that converts a digital number to an analog voltage proportional to the resolution of bit.

Basic SPI

The DACs are SPI Bus based which is a serial bus. So the number of pins in IC is very low. Total of 4 lines are required to interface it with TMS320C6745

☞MISO (Master In Slave Out)

☞MOSI (Master Out Slave In)

☞SCK (Serial Clock)

☞CS (Chip Select)

As you know in synchronous serial communication there is a clock line (SCK in case of SPI) which synchronizes the transfer.

The clock is always controlled by the MASTER. In our case the TMS320C6745 is the MASTER and the MCP4921 is a slave on the bus. SPI is full duplex that means data can be sent and received simultaneously.

MCP4921 devices are voltage output string DACs. These devices include input amplifiers, rail-to-rail out-put amplifiers, reference buffers, shutdown and reset-management circuitry. The coding of these devices is straight binary.

Analog Voltage Output

The analog voltage output produced by a D/A Converter is a function of the input digit and the reference voltage. For the MCP4921, Vref is used as the reference voltage. The theoretical Vout Analog voltage output produced by the D/A Converter is shown below.


VREF = reference voltage

G = Gain

DN = Input Digits

n = number of bit

Circuit Diagram to Interface SPI DAC with TMS320C6745

C Program to Interface SPI DAC with TMS320C6745 DSP




#include "c6745.h"

#include "spidac.h"


#define PI 3.14

#define    DAC_CS_LOW();   SPI_SPIPC3 = 0x0;   //(CS=Low:Enable)

#define    DAC_CS_HIGH();  SPI_SPIPC3 = 0x1;   //(CS=High:Disable)


void SPI_Write(unsigned short Data);

void Sent_to_SPI(unsigned short Value);


unsigned short i,j=0,High,Value=0;

const float sampf = 11000.0;     // Sampling frquency is fixed




const int inpf = 1000;   // change the input frquency from 1khz to 8khz(1000 to 8000)

float sampt;

double teta;

signed short value;

int count,nsamp;


void main()




  sampt = 1/sampf;

  nsamp = sampf/inpf;






                  teta = (2 * PI * inpf * sampt * count);

                  value = sin(teta)*2048;





void Sent_to_SPI(unsigned short Value)



  Value = (0x0FFF & Value);

  Value = (0x0800 ^ Value);




 SPI 16 bit Data to Dac
void SPI_Write(unsigned short Data)    


  unsigned short receive;

          Data = ( 0x3000 | Data );

          /* Clear any old data */

          receive = SPI_SPIBUF;

          // Wait for transmit ready

          while( SPI_SPIBUF & 0x10000000 );

          /* Write 1 byte */

          SPI_SPIDAT1 = Data;

          while((SPI_SPIBUF & 0x20000000)==1);

          receive = SPI_SPIBUF;


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.