How to Interface SPI-DAC with LPC2148

SPI-DAC Interfacing With ARM7 Slicker

Overall rating
ARM7 LPC2148 Slicker Board

The ARM7 LPC2148 Slicker board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through serial port.

NXP’s ARM7 (LPC2148), ARM Slicker Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 32-bit Microcontrollers.

SPI (Serial Peripheral Interface)

Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by microcontrollers for communicating with one or more peripheral devices quickly over short distances. It can also be used for communication between two microcontrollers.

DAC (Digital to Analog Converter)

A digital-to-analog converter is a device for converting a digital (usually binary) code to an analog signal (current, voltage or charges). Digital-to-Analog Converters are the interface between the abstract digital world and the analog real life. Simple switches, a network of resistors, current sources or capacitors may implement this conversion. A DAC inputs a binary number and outputs an analog voltage or current signal.


The Microchip Technology Inc. MCP492X is 2.7 – 5.5V, low-power, low DNL, 12-Bit Digital-to-Analog Converters (DACs) with optional 2x buffered output and SPI interface. The MCP492X are DACs that provide high accuracy and low noise performance for industrial applications where calibration or compensation of signals is required.

Interfacing SPI-DAC

Fig. 1 shows how to interface the SPI-DAC to microcontroller. With an SPI connection there is always one master device (usually a microcontroller) which controls the peripheral devices. Typically there are three lines common to all the devices,

  • Master In Slave Out (MISO) - The Slave line for sending data to the master,
  • Master Out Slave In (MOSI) - The Master line for sending data to the peripherals,
  • Serial Clock (SCK) - The clock pulses which synchronize data transmission generated by the master, and
  • Slave Select pin - the pin on each device that the master can use to enable and disable specific devices. When a device's Slave Select pin is low, it communicates with the master. When it's high, it ignores the master.

This allows you to have multiple SPI devices sharing the same MISO, MOSI, and CLK lines.



The resolution of the converter indicates the number of discrete values it can produce over the range of analog values. The values are usually stored electronically in binary form, so the resolution is usually expressed in bits. In consequence, the number of discrete values available, or "levels", is a power of two. For example, an ADC with a resolution of 10 bits can encode an analog input to one in 1024 different levels, since 210 = 1024. The values can represent the ranges from 0 to 1023 (i.e. unsigned integer) depending on the application.

Interfacing SPI-DAC with LPC2148

In SPI, the clock signal is controlled by the master device LPC2148 Slicker Board. All data is clocked in and out using this pin. These lines need to be connected to the relevant pins on the LPC2148 Slicker Board. Any unused GIO pin can be used for CS, instead pull this pin high. Conversion speed is the time it takes for the DAC to provide an analog output when the digital input word is changed. The MCP429x DAC - SPI connections with LPC2148 have four I/O lines (P0.4 – P0.7) required. The DAC output is generated analog output by using these four lines.

Pin Assignment with LPC2148



SPI Connector


Processor Lines














Circuit Diagram to Interface SPI-DAC with LPC2148


Source Code

The Interfacing SPI - DAC with LPC2148 program is very simple and straight forward, which generate the analog signal by using digital data’s in LPC2148 Slicker Board DAC through SPI. Some delay is occurring when a single data is sent through SPI to MCP429x. C programs are written in Keil software. The analog output is verified in MCP429x DAC controller.

C Program to interface SPI - DAC with LPC2148


Title : Program to generate analog signals




#include <LPC214X.H>


#include "SPIsw.h"

#include "Utility.h"


unsigned long DACval,DACreg;


int main (void)



   PINSEL0 = 0;

   PINSEL1 = 0;

   PINSEL2 &= 0x0000000C;


   SPI_init (&IOPIN0,29/*CS*/, 5/*MISO*/, 6/*MOSI*/,

   4/*SCK*/, 0/*CPOL*/, 0/*CPHA*/);


   // Set output voltage

   DACval = 2047;             // Range [0..4095]

   DACreg = DACval | 0x7000;


   SPI_enable ();

   SPI_char ((DACreg >> 8) & 0x00FF);

   SPI_char (DACreg & 0x00FF);

   SPI_disable ();


   // Endless loop

   while (1);




To compile the above C code you need the KEIL software. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In KEIL, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without LPC2148 Slicker Board.

The Flash Magic software is used to download the hex file into your microcontroller IC LPC2148 through UART0.

Testing the SPI-DAC with LPC2148

Give +3.3V power supply to LPC2148 Slicker Board; the SPI-DAC IC is connected with LPC2148 Slicker Board. Here we are generating a sine wave from o – 4096 data’s.

First, switch ‘ON’ the CRO. Touch the CRO probe in the DAC output line. Now the CRO should show the sine output.


General Information

  • For proper working use the components of exact values as shown in Circuit file. Wherever possible use new components.
  • Solder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints.
  • Use the exact value crystal shown in schematic.
  • More instructions are available in following articles,
       - User Manual of LPC2148 Slicker Board.
       - Tutorial of how to create & Debug a project in KEIL.

Join the World's Largest Technical Community

we respect your privacy.