Unit 3 EP DBA Final
Unit 3 EP DBA Final
Unit Objectives
1. To get acquainted with programming concept of LPC 2148 processor.
2. To understand interfacing of LPC2148 with various peripheral s.
3. To get insight of on chip peripheral s and its programming for LPC2148.
Books :
• R1: UM10139 LPC214x User manual, NXP Semiconductor
UART is one of the most simple and most commonly used Serial
Communication techniques.
❖ If you remember older computer systems, devices like Mouse, Printer and
Modem are connected using a heavy connectors at the back. All these devices
communicated using UART.
In parallel data transfer, all the bits are transferred from the source to destination at
once. This is possible because parallel data transfer uses multiple lanes or wires
between the transmitter and receiver in order to transfer the data.
Basics of UART Communication
❖ Basic about Parallel and Serial Communication
Parallel Data Transfer methods are faster and expensive as they needs more
hardware and a lot of wires. Olden day’s printers are the best example for
external parallel communication. Other examples are RAM, PCI, etc.
With the progress in integrated circuit technology, the digital IC’s are becoming
smaller and faster and as a result the transfer rates in Parallel Communication
with multiple lanes have reached a bottle neck.
Serial Communication on the hand, transfers data bit by bit using a single line or
wire. For two way communication between the transmitter and receiver, we
need just two wires for successful serial data transfer.
Basics of UART Communication
❖ Basic about Parallel and Serial Communication
Since serial communication needs less circuitry and wires, the cost of implementing
is less. As a result, using serial communication in complex circuitry might be more
practical than parallel communication.
But the only concern with serial data transfers is speed. Since the data transfer occurs
over a single line, the speed of transfer in serial communication is less than that of
parallel communication. Now – a – days, the speed of serial data transfer isn’t a
concern as advancements in technology have led to faster transfer speeds.
Introduction to UART Communication
UART or Universal Asynchronous Receiver Transmitter is a serial
communication device that performs parallel – to – serial data conversion at the
transmitter side and serial – to – parallel data conversion at the receiver side.
It is universal because the parameters like transfer speed, data speed, etc. are
configurable.
Since, UART is a piece of hardware that acts as a bridge between the processor
and the serial communication protocol or port as shown in fig below, The serial
communication can be anything like USB, RS232, etc.
Introduction to UART Communication
The letter ‘A’ in UART stands for Asynchronous i.e. there is no clock signal to synchronize or
validate the data transmitted from transmitter and received by the receiver (Asynchronous
Serial Communication).
This is in contrast to Synchronous Serial Communication, which uses a clock signal that is
shared between the transmitter and receiver in order to “Synchronize” the data between them.
If there is no clock (or any other timing signal) between the transmitter and receiver,
then how does the receiver know when to read the data?
In UART, the transmitter and receiver must agree on timing parameters beforehand. Also,
UART uses special bits at the beginning and ending of each data word to synchronize the
transmitter and receiver.
In UART based Serial Communication, the transmitter and receiver communicate in the
following manner.
1. The UART on the sender device i.e. the transmitting UART receives parallel data from
the CPU (microprocessor or microcontroller) and converts it in to serial data. This serial
data is transmitted to the UART on the receiver device i.e. receiving UART.
2. The receiving UART, upon receiving the serial data, converts it back to parallel data and
gives it to the CPU.
Introduction to UART Communication
The pin on the transmitting UART, which transmits the serial data is called TX and
the pin on the receiving UART, which receives the serial data is called RX.
Since the UART involves parallel – to – serial and serial – to – parallel data
conversion, shift registers are an essential part of the UART hardware.
Two shift registers to be specific:
1. Transmitter Shift Register
2. Receiver Shift Register.
How UART Works?
Instead of clock signal, UART uses some special bits called Start and Stop bits.
These bits are added to the actual data packet at the beginning and end
respectively. These additional bits allows the receiving UART to identify the
actual data.
How UART Works?
The transmitting UART receives data from the controlling device through the data
bus. The controlling device can be anything like a CPU of a microprocessor or a
microcontroller, memory unit like a RAM or ROM, etc.
The data received by the transmitting UART from the data bus is parallel data. To
this data, the UART adds Start, Parity and Stop bits in order to convert it into a data
packet.
The data packet is then converted from parallel to serial with the help of shift
register and is transmitted bit – by – bit from the TX pin.
The receiving UART receives this serial data at the RX pin and detects the actual
data by identifying the start and stop bits. Parity bit is used to check the integrity of
the data.
Up on separating the start, parity and stop bits from the data packet, the data is
converted to parallel data with the help of shift register. This parallel data is sent to
the controller at the receiving end through a data bus.
Structure of Data Packet or Frame
The data in UART serial communication is organised in to blocks called Packets or Frames.
The structure of a typical UART Data Packet or the standard framing of the data is shown in
the following fig.
a) Start Bit: Start bit is a synchronisation bit that is added before the actual data.
Start bit marks the beginning of the data packet. Usually, an idle data line i.e.
when the data transmission line is not transmitting any data, it is held at a high
voltage level (1).
In order to start the data transfer, the transmitting UART pulls the data line from
high voltage level to low voltage level (from 1 to 0). The receiving UART
detects this change from high to low on the data line and begins reading the actual
data. Usually, there is only one start bit.
Structure of Data Packet or Frame
b) Stop Bit: The Stop Bit, as the name suggests, marks the end of the data packet.
It is usually two bits long but often only on bit is used. In order to end the
transmission, the UART maintains the data line at high voltage (1).
c) Parity Bit: Parity allows the receiver to check whether the received data is
correct or not. Parity is a low – level error checking system and comes in two
varieties: Even Parity and Odd Parity. Parity bit is optional and it is actually not
that widely used.
d) Data Bits: Data bits are the actual data being transmitted from sender to
receiver. The length of the data frame can be anywhere between 5 and 9 (9 bits if
parity is not used and only 8 bits if parity is used). Usually, the LSB is the first
bit of data to be transmitted.
Rules of UART
As, there is no clock signal in UART and the transmitter and receiver must agree on
some rules of serial communication for error free transfer of data.
The rules include:
▪ Synchronisation Bits (Start and Stop bits)
▪Parity Bit
▪Data Bits
▪Baud Rate
Baud Rate: The speed at which the data is transmitted is mentioned using Baud
Rate. Both the transmitting UART and Receiving UART must agree on the Baud
Rate for a successful data transmission.
Baud Rate is measured in bits per second. Some of the standard baud rates are 4800
bps, 9600 bps, 19200 bps, 115200 bps etc. Out of these 9600 bps baud rate is the
most commonly used one.
• Let us see an example data frame where two blocks of data i.e. 00101101 and
11010011 must be transmitted. The format of the frame is 9600 8N1 i.e. 9600
bps with 8 bits of data, no parity and 1 stop bit. In this example, we haven’t used
the parity bit.
❑ The asynchronous serial protocol has a number of built-in rules -
mechanisms that help ensure robust and error-free data transfers.
✔ Data bits
✔ Synchronization bits
✔ Parity bits
✔ Baud rate.
❑ The baud rate specifies how fast data is sent over a serial line.
It’s usually expressed in units of bits-per-second (bps).
Framing the data
❑ Each block (usually a byte) of data transmitted is actually sent in
a packet or frame of bits. Frames are created by appending
synchronization and parity bits to our data.
A serial frame.
Since we’re transferring at 9600 bps, the time spent holding each
of those bits high or low is 1/(9600 bps) or 104 µs per bit.
Wiring and Hardware
❑ A serial bus consists of just two wires - one for sending data and
another for receiving. As such, serial devices should have two
serial pins: the receiver, RX, and the transmitter, TX.
Hardware Implementation
❑ RS-232, which can be found on some of the more ancient
computers and peripherals, is like TTL serial flipped on its head.
❑ RS-232 signals usually range between -13V and 13V, though the
spec allows for anything from +/- 3V to +/- 25V.
❑ On these signals a low voltage (-5V, -13V, etc.) indicates either
the idle line, a stop bit, or a data bit of value 1.
❑ A high RS-232 signal means either a start bit, or a 0-value data
bit. That’s kind of the opposite of TTL serial.
❑ The MAX232 is an IC originally designed by a company called
Maxim IC that converts the +/-13V(+/-25V) signals of RS232
down to the 0/5V signals that our Microcontroller can understand.
❑ It also boosts the voltage of our Microcontroller to the needed
+/-13V(+/-25V) of the RS232 protocol so that a computer can
understand our Microcontroller and vice versa.
RS232 Protocol
https://www.electronicshub.org/
https://binaryupdates.com/uart-in-lpc2148-arm7/
Voltage Levels
RS232 was defined way before TTL logic and hence, it is not
unexpected that RS232 doesn’t use the TTL specific 5V and GND
logic levels.The logic ‘1’ in RS232 is described as being in the
voltage range of -15V to -3V and logic ‘0’ is described as the voltage
range of +3V to +15V i.e. low level voltage is logic ‘1’ and high level
voltage is logic ‘0’. Typically, the logic ‘1’ in RS232 will be -12V and
logic ‘0’ will be +12V.
List of UART in
LPC2148
UART section of LPC 2148:
● The LPC 2148 contains two UARTs which are compatible with
UART IC 16C550 (Industry Standard UART IC).
● UART0 provides only standard transmit and receive data lines
● UART1 also provides a full modem control handshake interface
along with standard transmit and receive data lines.
LPC214x UART0
Features:
● 16 byte Receive and Transmit FIFOs
● Register locations conform to ‘550 industry standard.
● Receiver FIFO trigger points at 1, 4, 8, and 14 bytes.
● Built-in fractional baud rate generator with autobauding
capabilities.
● Mechanism that enables software and hardware flow control
implementation.
UART0 block diagram
LPC214x UART1
Features
● UART1 is identical to UART0, with the addition of a modem
interface.
● 16 byte Receive and Transmit FIFOs.
● Register locations conform to ‘550 industry standard.
● Receiver FIFO trigger points at 1, 4, 8, and 14 bytes.
● Built-in fractional baud rate generator with autobauding capabilities.
● Mechanism that enables software and hardware flow control
implementation.
● Standard modem interface signals included with flow control
(auto-CTS/RTS) fully supported in hardware (LPC2144/6/8 only).
UART1 block diagram
#include<LPC21xx.h>
void main()
{
char a;
VPBDIV=0x00 // 15 MHz freq.
PINSEL0=0x00000005;//P0.0 as TxD0 & P0.1 as RxD0
IODIR0 = 0x01
U0LCR=0x83;//8 -bit character length,DLAB=1
U0DLM=0x00;//
U0DLL=0x61;// Baud rate=9600
U0LCR=0x03;// DLAB=0; to load baud rate value
while(1)
{
while(!(U0LSR&0x01)); //monitoring RI flag
a=U0RBR;
3/26/2025 51
Global System for Mobile Communication
• GSM (Global System for Mobile Communications) is the
technology that underpins most of the world's mobile phone
networks.
• GSM is an open, digital cellular technology used for transmitting
mobile voice and data services.
• The SIM300 module is a Triband GSM/GPRS solution in a compact
plug in module featuring an industry-standard interface
• GSM operates in the 900MHz and 1.8GHz bands GSM supports
data transfer speeds of up to 9.6 kbps, allowing the transmission of
basic data services such as SMS.
3/26/2025 52
Features of GSM MODEM
•Single supply voltage 3.2v-4.5v
•Typical power consumption in SLEEP Mode: 2.5mA.
•SIM300 tri-band
•MT,MO,CB, text and PDU mode, SMS storage: SIM
card
•Supported SIM Card :1.8V,3V
3/26/2025 53
GSM Module: Block Diagram
3/26/2025 54
GSM Module
3/26/2025 55
GSM Mobile Vs GSM Module
• A GSM mobile is a complete system in itself with embedded processors that are
dedicated to provide an interface between the user and the mobile network.
• The AT commands are served between the processors of the mobile termination and the
terminal equipment.
• The mobile handset can also be equipped with a USB interface to connect with a
computer, but it may or may not support AT commands from the computer or an external
processor/controller.
• The GSM/GPRS module, on the other hand, always needs a computer or external
processor/controller to receive AT commands from.
• GSM/GPRS module itself does not provide any interface between the user and the
network, but the computer to which module is connected is the interface between user
and network.
• An advantage that GSM/GPRS modules offer is that they support concatenated (link
(things) together in a chain or series) SMS which may not be supported in some GSM
mobile handsets
• Applications of GSM/GPRS module:
The GSM/GPRS module demonstrates the use of AT commands. They can feature
all the functionalities of a mobile phone through computer like making and receiving
calls, SMS, MMS etc. These are mainly employed for computer based SMS and MMS
services.
3/26/2025 56
GSM modem: Overview
A GSM modem is a wireless modem that works with a GSM wireless
network. A wireless modem behaves like a dial-up modem. The main
difference between them is that a dial-up modem sends and receives data
through a fixed telephone line while a wireless modem sends and receives
data through radio waves.
Like a GSM mobile phone, a GSM modem requires a SIM card from a
wireless carrier in order to operate.
3/26/2025 58
AT commands :Overview
AT commands are instructions used to control a modem. AT is the abbreviation
of ATtention.
Every command line starts with "AT" or "at". That's why modem commands are
called AT commands.
The AT is an ATTENTION command and is used as a prefix to other parameters
in a string. The AT command combined with other parameters can be set up in the
communications package or typed in manually as a command line instruction.
Many of the commands that are used to control wired dial-up modems, such as
ATD (Dial), ATA (Answer), ATH (Hook control) and ATO (Return to online
data state), are also supported by GSM/GPRS modems and mobile phones.
The starting "AT" is the prefix that informs the modem about the start of
a command line. It is not part of the AT command name.
For example, D is the actual AT command name in ATD and +CMGS is
the actual AT command name in AT+CMGS. However, some books and
web sites use them interchangeably as the name of an AT command.
3/26/2025 60
AT commands :Overview
1. Basic commands:
Basic commands are AT commands that do not start with “+”. For
example, D(Dial), we can write the command for dialing a call as
ATD. Similarly for A(Answer), H(hook control) and O(Return to
online data state) we can use the commands ATA, ATH and ATO
respectively.
2. Extended commands :
Extended commands are AT commands that start with “+”. All GSM
AT commands are extended commands. For example, +CMGS(Send
SMS message), +CMSS(Send SMS message from storage),
+CMGL(List SMS messages) and +CMGR( Read SMS message) are
some of the extended commands.
3/26/2025 61
AT commands :Overview
• These commands come from Hayes commands that were used by the Hayes
smart modems.
• The Hayes commands started with AT to indicate the attention from the
MODEM.
•Hayes commands developed by Dennis Hayes for the Hayes Smartmodem 300
baud modem in 1981.
3/26/2025 62
GSM AT Commands and their functions
GSM AT Commands and their functions
AT Command Function of AT Command
ATD Dial
AT+CGMS Send SMS Message
3/26/2025 63
GSM AT Commands and their functions
AT command Description
This command is used to check communication between the
AT
module and the computer.
AT+CMGF=< set the SMS mode(PDU mode or text mode).
mode>
AT+CMGF Message format
AT+CMGL List messages
AT+CMGR Read message
AT+CMGS Send message
AT+CMSS Send message from storage
AT+CMGW Write message to memory
AT+CMGD Delete message
GSM AT Commands and their functions
-Set functionality to various modes such as GSM, CDMA and
LTE. It is mainly used in modem providing multi-RAT
AT +CFUN=value support.
-Value=some number 0 to 6 or more. 1 means full
functionality
ATD <number> used to call a phone number.
ATA used to answer an incoming call
ATH used to disconnect the established call
AT+CGDCONT=1,"IP AT command to define PDP context,APN is gateway between
address","APN" GPRS network & internet.
AT+COPS=1,2,26201 Manual PLMN selection
AT+COPS? Will provide PLMN information set in the modem
AT+CGMR Display the version of the software loaded on the modem
Used to activate and deactivate GPRS or PS connection
AT+CGATT AT+CGATT=0 deactivates and AT+CGATT=1 activates the
GPRS
AT commands:Operations
There are total 4 types of AT commands in terms of their operation:
1.Test operation:
A test operation is used to check whether a certain AT command is
supported by the GSM/GPRS modem or mobile phone.
2. Set operation:
A set operation is used to change the settings used by the
GSM/GPRS modem or mobile phone for certain tasks.
3. Read operation:
A read operation is used to retrieve the current settings used by the
GSM/GPRS modem or mobile phone for certain tasks.
The supported values of each of the four parameters are enclosed in parentheses.
Commas are used to delimit the parentheses and the values inside parentheses. A
hyphen is used to indicate a range of values. The values inside parentheses can be of
the string type.
In the above example, the response of the test command "+COMMAND1=?"
provides us the following information:
(0,1). The first parameter accepts either 0 or 1.
(0-10). The second parameter accepts any integer between 0 and 10.
(0,1,5-10). The third parameter accepts 0, 1 or any integer between 5 and 10.
("GSM","UCS2"). The fourth parameter accepts either the string "GSM" or "UCS2".
3/26/2025 68
Test Operation
To a few AT commands, the test operation does not return the parameter values supported.
Instead, it returns the values that are allowed to appear in the information response of the AT
command. An example is the +CBC AT command (command name in text: Battery Charge).
The +CBC command is used to retrieve the connection status and charge level of the battery of
the mobile device. Two values are returned in the information response of the +CBC AT
command. The format is:
+CBC: connection_status,charge_level
For example, if the battery is placed in the mobile device with no charger connected and the
charge level is 80%, the result of the execution of the +CBC AT command will be:
AT+CBC
+CBC: 0,80
OK
If you run the test command "+CBC=?", all the supported values that are allowed to appear in
the connection status field and charge level field will be provided. With Nokia 6021, the result
is:
AT+CBC=?
+CBC: (0,1),(0-100)
OK
"(0,1)" means the connection status field in the information response of the +CBC AT
command can contain either 0 or 1, while "(0-100)" means the charge level field can contain
any 3/26/2025
integer between 0 and 100 69
Set Command:
A set operation changes the settings used by the GSM/GPRS modem or mobile
phone for certain tasks.
The syntax is:
command=value1,value2,...valueN
where command is an AT command and value1 to valueN are the values you want to
set. When an AT command is used in the above syntax to perform a set operation, it
is called a set command.
Typically the values you specified with set commands are placed in volatile
memory. If the GSM/GPRS modem or mobile phone is switched off or rebooted, the
values you specified with set commands will be gone. When the GSM/GPRS
modem or mobile phone is powered on again, all settings are back to the defaults.
For some commonly used settings, there are AT commands for saving/restoring the
settings to/from non-volatile memory. For example, the AT commands +CSAS
(command name in text: Save Settings) and +CRES (command name in text:
Restore Settings) can be used to save and restore settings related to SMS messaging
such as the SMS center address.
3/26/2025 71
Read Command:
A read operation retrieves the current settings used by the GSM/GPRS modem or
mobile phone for certain tasks.
The syntax is:
command?
where command is an AT command. When an AT command is used in the above syntax
to perform a read operation, it is called a read command. The read operation is
supported by all AT commands that are capable of the set operation.
Here is an example that illustrates how to use a read command. The AT command
+CSCA (command name in text: Service Centre Address) is used to set the SMSC
(SMS center) address for sending SMS messages. It takes two parameters that specify
the SMSC address and type of address.
Suppose you set the SMSC address to +85291234567 in the HyperTerminal, like this:
AT+CSCA="+85291234567",145
OK
After that, if you enter the read command "+CSCA?", the GSM/GPRS modem or
mobile phone will return the SMSC address and type of address that you set in the
previous step:
AT+CSCA?
+CSCA: "+85291234567",145
3/26/2025 72
OK
Execution Command:
An execution operation is used to perform an action (for example, send or read an
SMS message) or retrieve information/status about the GSM/GPRS modem or mobile
phone (for example, retrieve the current battery charge level, battery charging status
or radio signal strength of the mobile network).
The syntax is:
command=value1,value2,...valueN
where command is an AT command and value1 to valueN are the values to assign to
the AT command. If the AT command does not have any parameters, the part
"=value1,value2,...valueN" should be omitted. When an AT command is used in the
above syntax to perform an execution operation, it is called an execution command.
Unlike set commands, execution commands do not store the parameter values
assigned to them. So, no read command is available for retrieving the last
parameter values assigned to an execution command. For example, if you send the
command line "AT+CMSS?" to your GSM/GPRS modem or mobile phone, the
ERROR result code will be returned:
AT+CMSS?
ERROR
3/26/2025 74
Interfacing GSM with LPC2148
The GSM module is communicate the microcontroller with mobile phones through
UART. To communicate over UART or USART, we just need three basic signals which
are namely, RXD (receive), TXD (transmit), GND (common ground).
3/26/2025 75
Interfacing GSM with LPC2148
Text message may be sent through the modem by interfacing only
three signals of the serial interface of modem with microcontroller
i.e., TxD, RxD and GND. In this scheme RTS and CTS signals of
serial port interface of GSM Modem are connected with each other.
The SMS message in text mode can contain only 140 characters at
the most. It depends upon the amount of information collected from
GPS Engine that you need at the base station for tracking vehicle or
person.
3/26/2025 76
Interfacing GSM with LPC2148
Display a text in mobile from LPC2148 Development by using GSM module through
UART. In LPC2148 Development contains two serial interfaces that are UART0 &
UART1. Here we are using UART0. The GSM modem is being interfaced with the
microcontroller LPC2148 Development for SMS communication. The SMS can be
sending and receiving for the data sharing and situation information and control.
3/26/2025 77
Pin assignment with LPC 2148
Pin Assignments
TXD-1 P0.8
UART1 (P2)
RXD-1 P0.9
3/26/2025 78
Interfacing of GSM Module
3/26/2025 79
Algorithm for GSM module interfacing with LPC2148
1) Start
6) To transmit a single character use PUTCH function & to transmit a string use PUTS
function
7) END
3/26/2025 80
Interfacing of LPC2148 with GSM module
#include<lpc21xx.h> //Includes LPC2148 register
definitions #include "serial.h"
unsigned char GsmSendMsg(unsigned char *msgStr);
void DelayMs(unsigned int count);
int main(void)
{
Uart0Init();
Uart0PutS("ATE0\r\n"); //Turn echo off
DelayMs(500);
Uart0PutS("ATD9503XXXXXX;\r\n"); //replace xxxxxxxxxx with
number to call
DelayMs(20000);
Uart0PutS("ATH0\r\n"); //disconnect call
DelayMs(3000);
GsmSendMsg(“HELLO");
while(1);
}
unsigned char GsmSendMsg(unsigned char *msgStr)
{
Uart0PutS("AT+CMGF=1\r\n");//Send SMS: Select Text mode
DelayMs(100);
Uart0PutS("AT+CMGS=\"9503XXXXXX\"\r\n"); //Send SMS to mobile number
DelayMs(100);
Uart0PutS(msgStr);
DelayMs(100);
Uart0PutCh(0x1A); //CNTL + Z
DelayMs(3000);
return (1);
}
❖GPS has become a vital global utility, indispensable for modern navigation on land, sea,
and air around the world, as well as an important tool for map-making and land
surveying. GPS also provides an extremely precise time reference, required for
telecommunications and some scientific research, including the study of earthquakes.
Applications
1. Military
2. Navigation
3. Location-based services
4. Location-based games
5. Aircraft passengers
6. Surveying
7. Agriculture
8. Geophysics and geology
9. 3/26/2025
Precise time reference 84
3/26/2025 85
3/26/2025 86
GPS module interfacing:Overview
You have probably used or benefited from a GPS receiver. They are
found in most smart phones, many new automobiles, and they are
used to track commerce all over the globe. These tiny devices can
instantaneously give your exact position and time, almost anywhere
on the planet, for free! All you need is a GPS receiver, and receivers
are getting less expensive and smaller every day.
3/26/2025 87
GPS module interfacing:Working
At any given time, there are at least 24 active satellites orbiting over
12,000 miles above earth. The positions of the satellites are
constructed in a way that the sky above your location will always
contain at most 12 satellites. The primary purpose of the 12 visible
satellites is to transmit information back to earth over radio
frequency (ranging from 1.1 to 1.5 GHz). With this information and
some math, a ground based receiver or GPS module can calculate its
position and time.
3/26/2025 88
How does a GPS receiver calculate its position and time?
The data sent down to earth from each satellite contains a few different pieces
of information that allows your GPS receiver to accurately calculate its
position and time. An important piece of equipment on each GPS satellite is an
extremely accurate atomic clock. The time on the atomic clock is sent down to
earth along with the satellite’s orbital position and arrival times at different
points in the sky. In other words, the GPS module receives a time stamp from
each of the visible satellites, along with data on where in the sky each one is
located (among other pieces of data). From this information, the GPS receiver
now knows the distance to each satellite in view. If the GPS receiver’s antenna
can see at least 4 satellites, it can accurately calculate its position and time.
This is also called a lock or a fix.
There is another piece of the global positioning system we haven’t talked
about. Along with satellites and GPS receivers, there are ground based stations
that can communicate with the satellite network and some GPS receivers. This
system is formally called the control segment and increases the accuracy of
your GPS receiver. Common systems that use the control segment to improve
accuracy are WAAS and DGPS. WAAS is common on most GPS receivers
and improves accuracy to about 5 meters. DGPS requires a specific type of
GPS receiver and gets centimetre accuracy. DGPS units are also expensive and
3/26/2025 89
tend to be larger because they require an additional antenna.
GPS Accuracy
GPS Accuracy depends on a number of variables, most notably
signal to noise ratio (noisy reception), satellite position, weather and
obstructions such as buildings and mountains. These factors can
create errors in your perceived location. Signal noise usually creates
an error from around one to ten meters. Mountains, buildings and
other things that might obstruct the path between the receiver and the
satellite can cause three times as much error as signal noise. A GPS
receiver must be able to get a lock on 4 satellites to be able to solve
for a position. The first lock it gets allows the receiver to obtain the
almanac information and thus what other satellites it should listen
for. Although it is possible to get a position from less than 4
satellites, the margin of error of this position can be rather large.
Your most accurate read of your location comes when you have a
clear view of a clear sky away from any obstructions and under more
than four satellites. To combat these errors, a couple of different
assistants have been created.
3/26/2025 90
Differential GPS
Another method is Differential GPS or DGPS. DGPS also uses ground or fixed GPS
stations to determine the location, but differs in that it finds the difference between both the
satellite and the ground location reading. These ground stations may be up to 200 nautical
miles from the receiver, and it is important to note that accuracy deteriorates the further you
are from the ground station. DGPS is accomplished by a ground station broadcasting a signal
which dictates the error between the actual pseudo range and the measured pseudo range. This
value is calculated by multiplying the speed of light by the time it takes the signal to travel
from the satellite to the receiver. As an example, one form of DGPS is Wide Area
Augmentation System or WAAS.
.
•A nautical mile is a unit of length used in air, marine,
and space navigation.
A nautical mile is based on the circumference of the
earth, and is equal to one minute of latitude. It is slightly
more than a statute (land measured) mile (1 nautical
mile = 1.1508 statute miles ).
3/26/2025 91
Differential GPS
Originally developed by the FAA to assist aircraft GPS, WAAS uses a system of
specifically built ground stations. WAAS holds a specific set of accuracy standards that
ground station measurements must meet. Laterally and vertically, WAAS must be accurate
to within 7.6 meters 95% of the time. These ground stations send their measurements to
master stations which send the corrections to WAAS satellites every 5 seconds or quicker.
From the Satellite, a signal is broadcast back to the receivers on earth where the
corrections are used to improve the GPS accuracy. In some locations, WAAS is able to
provide an accuracy of 1 meter lateral and 1.5 meters vertically. While WAAS is only
present in North America, similar systems are in place in many other parts of the world
3/26/2025 92
The NMEA 0183 Protocol
❖The National Marine Electronics Association (NMEA) is a non-profit
association of manufacturers, distributors, dealers, educational
institutions, and others interested in peripheral marine electronics
occupations. The NMEA 0183 standard defines an electrical interface
and data protocol for communications between marine instrumentation.
❖NMEA 0183 is a voluntary industry standard, first released in March of
1983. It has been updated from time to time; the latest release, currently
(August 2001) Version 3.0, July 2001, is available from the NMEA office
(www.nmea.org)
❖NMEA has also established a working group to develop a new standard
for data communications among shipboard electronic devices. The new
standard, NMEA 2000, is a bi-directional, multi-transmitter,
multi-receiver serial data network. It is multi-master and
self-configuring, and there is no central controller.
3/26/2025 93
NMEA Output Messages
Table 1.1 – NMEA-0183 Output
Messages
3/26/2025 94
NMEA Output Messages
1. GGA – Global Positioning System Fixed Data
$GPGGA,161229.487,3723.2475,N,12158.3416,W,1,07,1.0,9.0,M,,,,0000*18
Table 1.2 – GGA Data
Format
3/26/2025 95
NMEA Output Messages
2. GLL – Geographic Position – Latitude/Longitude
$GPGLL, 3723.2475,N,12158.3416,W,161229.487,A*2C
3/26/2025 96
Message Formats
GPS Configuration
GPS data is displayed in different message formats over a serial interface. There are standard
and non-standard (proprietary) message formats. Nearly all GPS receivers output NMEA data.
The NMEA standard is formatted in lines of data called sentences. Each sentence contains
various bits of data organized in comma delimited format (i.e. data separated by commas).
Here’s example NMEA sentences from a GPS receiver with satellite lock (4+ satellites,
accurate position):
$GPRMC,235316.000,A,4003.9040,N,10512.5792,W,0.09,144.75,141112,,*19
$GPGGA,235317.000,4003.9039,N,10512.5793,W,1,08,1.6,1577.9,M,-20.7,M,,0000*5F
$GPGSA,A,3,22,18,21,06,03,09,24,15,,,,,2.5,1.6,1.9*3E
Once a GPS module is powered, NMEA data (or another message format) is sent out of a
serial transmit pin (TX) at a specific baud rate and update rate, even if there is no lock. To
have your microcontroller read the NMEA data, all that is needed is to connect the TX pin of
the GPS to the RX (receive) pin on the microcontroller. To configure the GPS module, you
will need to also connect the RX pin of the GPS to the TX pin of the microcontroller.
It is common for the microcontroller to parse the NMEA data. Parsing is simply removing the
chunks of data from the NMEA sentence so the microcontroller can do something useful with
the data.
For example, the microcontroller might need to read only the altitude of your GPS.
$GPGGA,235317.000,4003.9039,N,10512.5793,W,1,08,1.6,1577.9,M,-20.7,M,,0000*5F
Instead of dealing with all of this text, the microcontroller can parse the GPGGA sentence
and end up with only the altitude (in meters).
1577
Once the microcontroller can grab the data needed, the information can be manipulated to
3/26/2025 98
create other interactions on the microcontroller.
Reading GPS data
2. Connecting to a Computer
A simple way to see the NMEA data directly is to connect the GPS module to a
computer. For the connections, all that is needed is to power the GPS with the FTDI
basic (in this case 5V and GND), then connect the TX pin of the GPS to the RX pin on
the FTDI Basic.
Next, open a serial terminal program at the same baud rate of your GPS module. Even
if the GPS does not have a lock, you should see NMEA sentences steaming by.
$GPRMC,235316.000,A,4003.9040,N,10512.5792,W,0.09,144.75,141112,,*19
$GPGGA,235317.000,4003.9039,N,10512.5793,W,1,08,1.6,1577.9,M,-20.7,M,,0000*
5F
$GPGSA,A,3,22,18,21,06,03,09,24,15,,,,,2.5,1.6,1.9*3E
3/26/2025 99
Configuring a GPS receiver
• To configure a GPS receiver, knowing the type of chipset your GPS is using is
very important. The GPS chipset contains a powerful processor that is
responsible for the user interface, all of the calculations, as well as analog
circuitry for the antenna. The chipset also allows for data to be sent to the GPS
receiver to configure parameters like, update rate, baud rate, sentence selection,
etc.
• In order to send commands over a serial interface to a GPS receiver, you will
need a command set or reference manual. In our case, we have used SkyTraq
chipsets.
• When communicating with a GPS receiver, most commands need to be
terminated by a checksum. In most cases, you need to XOR each of your
sentences.
3/26/2025 100
LPC2148 Interfacing with ADC using VIC
❖Analog Digital Converter
∙Features of ADC
∙ADC Functional Block Diagram
∙ADC Registers
❖Examples
∙Embedded C Program for on-chip ADC using interrupt
3/26/2025 101
On-chip ADC using interrupt (VIC)
Introduction to ADC
Analog to Digital Converter(ADC) is used to convert analog signal into digital
form. LPC2148 has two inbuilt 10-bit ADC i.e. ADC0 & ADC1.
ADC0 has 6 channels &ADC1 has 8 channels.
Hence, we can connect 6 distinct types of input analog signals to ADC0 and 8
distinct types of input analog signals to ADC1.
Features of ADC
• 10 bit successive approximation analog to digital converter.
• Input multiplexing among 6 or 8 pins (ADC0 and ADC1).
• Power-down mode.
• Measurement range 0 V to VREF (typically 3 V; not to exceed VDDA voltage level).
• 10 bit conversion time 2.44 µs.
• Burst conversion mode for single or multiple inputs.
• Optional conversion on transition on input pin or Timer Match signal.
• Global Start command for both converters.
3/26/2025 103
Analog Digital Converter
3/26/2025
Functional Block 104
Diagram
Analog Digital Converter
Block Explanation
Block Symbol Description I/O
AD0.1 Channel 1 P0.28
AD0.2 Channel 2 P0.29
AD0.3 Channel 3 P0.30
ADC0
AD0.4 Channel 4 P0.25
AD0.6 Channel 6 P0.4
AD0.7 Channel 7 P0.5
AD1.0 Channel 0 P0.6
AD1.1 Channel 1 P0.8
AD1.2 Channel 2 P0.10
AD1.3 Channel 3 P0.12
ADC1
AD1.4 Channel 4 P0.13
AD1.5 Channel 5 P0.15
AD1.6 Channel 6 P0.21
AD1.7 Channel 7 P0.22
3/26/2025 105
Register description
Register description
A/D Data Registers (ADDR0 to ADDR7, ADC0: AD0DR0 to AD0DR7
-
0xE003 4010 to 0xE003 402C and ADC1: AD1DR0 to AD1DR7- 0xE006
0010 to 0xE006 402C)
The A/D Data Register hold the result when an A/D conversion is
complete, and also include the flags that indicate when a conversion has
been completed and when a conversion overrun has occurred
ADC Registers
1) Control Register(AD0CR)
•AD0CR is a 32-bit register.
•This register must be written to select the operating mode before A/D conversion can
occur.
•It is used for selecting channel of ADC, clock frequency for ADC, number of clocks
or number of bits in result, start of conversion and few other parameters.
•7-0 SEL: Selects which of the AD0.7:0/AD1.7:0 pins is (are) to be sampled and
converted. For AD0, bit 0 selects Pin AD0.0, and bit 7 selects pin AD0.7. In
software-controlled mode, only one of these bits should be 1. e.g. bit 7 (10000000)
selects AD0.7 channel as analog input. In hardware scan mode, any value containing
1 to 8 one. All zeroes is equivalent to 0x01.
•These bits select ADC0 channel as analog input.
3/26/2025 112
ADC Registers
1) Control Register
•15-8 CLKDIV: The APB clock (PCLK) is divided by (this value plus one) to
produce the clock for the A/D converter, which should be less than or equal to
4.5 MHz Typically, software should program the smallest value in this field that
yields a clock of 4.5 MHz or slightly less, but in certain cases (such as a
high-impedance analog source) a slower clock may be desirable.
∙The A/D Converters on the LPC2148 is also called as The conversion speed
is selectable by the user
A/D Clock frequency= [Pclk/(CLKDIV+1)] .....................<=4.5 MHz
ADC Registers
1) Control Register
RESERVE EDGE START -- PDN -- CLKS BURST CLKDIV SEL
Bit 16 : BURST
3/26/2025 114
ADC Registers
1) Control Register
RESERVE EDGE START -- PDN -- CLKS BURST CLKDIV SEL
•Bit 20 – RESERVED
•21 PDN
∙PDN=0 The A/D converter is in power-down mode.
∙PDN=1 The A/D converter is operational.
3/26/2025 116
1) Control Register
RESERVE EDGE START -- PDN -- CLKS BURST CLKDIV SEL
Bit 30 – Overrun
This bit is set to 1 in burst mode if the result of one or more conversions is
lost and overwritten before the conversion that produced the result in
the RESULT bits.
This bit is cleared by reading this register.
Bit 16 – ADINT
This bit is 1 when any of the individual A/D channel DONE flags is asserted and enables ADC
interrupt if any of interrupt is enabled in AD0INTEN register.
BURST (Bit 16), START (Bit <26:24>) & EDGE (Bit 27)
These bits have same function as in the individual ADC control registers i.e.
AD0CR & AD1CR. Only difference is that we can use these function for both
ADC commonly from this register.
ADC Registers
5) Interrupt Enable : AD0INTEN (ADC0 Interrupt Enable)
Bit 0 – ADINTEN0
0 = Completion of a A/D conversion on ADC channel 0 will not generate an
interrupt
1 = Completion of a conversion on ADC channel 0 will generate an interrupt
Remaining ADINTEN bits have similar description as given for ADINTEN0.
Bit 8 – ADGINTEN
0 = Only the individual ADC channels enabled by ADINTEN7:0 will generate
interrupts
1 = Only the global DONE flag in A/D Data Register is enabled to generate an
interrupt
ADC Registers
6) Data Registers : AD0DR0-AD0DR7 (ADC0 Data Registers)
A/D Global Data Register: This register contains the ADC’s DONE
ADxGDR
bit and the result of the most recent A/D conversion
ADxDR0 - A/D Channel Data Register: Contains the recent ADC value for
ADxDR7 respective channel
A/D Status Register: Contains DONE & OVERRUN flag for all the
ADxSTAT
ADC channels
A/D Global Start Register: This address can be written (in the AD0
ADxGSR address range) to start conversions in both A/D converters
simultaneously.
ADC Registers
6) Interrupt Enable Register
• Enables interrupt on EOC channel
Examples
1.Select ADC-0, Channel-1, Clock frequency 3.75 MHz (let PCLK
is 15 MHz), burst mode repeated conversion and 10-bit resolution.
Power-up ADC and issue start of conversion.
3/26/2025 125
Steps for Configuring ADC
Below are the steps for configuring the LPC1768 ADC.
1. Configure the GPIO pin for ADC function using PINSEL register.
2. Enable the Clock to ADC module.
3. Deselect all the channels and Power on the internal ADC module
by setting ADCR.PDN bit.
4. Select the Particular channel for A/D conversion by setting the
corresponding bits in ADCR.SEL
5. Set the ADCR.START bit for starting the A/D conversion for
selected channel.
6. Wait for the conversion to complete, ADGR.DONE bit will be set
once conversion is over.
7. Read the 10-bit A/D value from ADGR.RESULT.
8. Use it for further processing or just display on LCD.
3/26/2025 126
Embedded C Program for on-chip ADC using interrupt
#include<lpc21xx.h>
#include<board.h>
void timer0(void)__attribute__((interrupt("IRQ")));
void timer0(void)
{
int adcdata; *T0IR = 0X01;
while(!(*ADDR&0X80000000));///////check status of DONE bit
adcdata = (*ADDR&0X0000FFC0);
adcdata = adcdata >> 6;
q_printf("timer 0 interrupt");
q_printf(" adcdata= %x \n ",adcdata);
*VICVectAddr = 0X00; /////Holds ISR addr of active interrupt.
Writing any value indicates End of Interrupt
}
3/26/2025 127
int main() Embedded C Program for on-chip ADC using interrupt
{
//////
*PINSEL1 = *PINSEL1 & 0XFCFFFFFF;
*PINSEL1 =*PINSEL1 | 0X01000000;////////ADC0.1.....P0.28 pin as ADC
i/p
*ADCR = 0X01210302;
*VICVectCntl0 = 0X24; //////VICVectCntlx=VIQ SLOT 0,Timer0
IRQ(BITS 0 to 4),VIQ (BIT 5)
*VICIntEnable = 0X10; //////High bit enables FIQ or IRQ classified
interrupts(Enable Timer 0 IRQ/FIQ Interrupt)
*T0IR = 0X01;
*T0MCR = 0X03;
*T0MR0 = 0X00E4E1C0;
*T0TCR = 0X01; /////Enable timer
*VICVectAddr0 = (unsigned int)timer0; //////Holds ISR address of timer0
while(1);
return 0;
}
3/26/2025 128
❑ Interrupt : “An interrupt is a signal sent to the CPU which
indicates that a system event has a occurred which needs
immediate attention”.
❑ Interrupt ReQuest (IRQ) can be thought of as a special request
to the CPU to execute a function(small piece of code) when an
interrupt occurs.
❑ ISR : This function or ‘small piece of code’ is technically called
an ‘Interrupt Service Routine‘ or ‘ISR’.
❑ So when an IRQ arrives to the CPU, it stops executing the
current code and start executing the ISR. After the ISR
execution has finished the CPU gets back to where it had
stopped.
Interrupts are handled by Vectored Interrupt Controller(VIC)
LPC214x VIC
Features
● ARM PrimeCell Vectored Interrupt Controller
● 32 interrupt request inputs
● 16 vectored IRQ interrupts
● 16 priority levels dynamically assigned to interrupt requests
● Software interrupt generation
Interrupt structure of LPC2148
❑ The VIC is a component from the ARM prime cell.
❑ VIC module is a highly optimised interrupt controller.
❑ The VIC is used to handle all the on-chip interrupt sources from
peripherals.
❑ Each of the on-chip interrupt sources is connected to the VIC on a fixed
channel: your application software can connect each of these channels to
the CPU interrupt lines (FIQ, IRQ) in one of three ways.
Interrupt structure of LPC2148
❑ The VIC allows each interrupt to be handled as an FIQ interrupt, a
vectored IRQ interrupt, or a non vectored IRQ interrupt.
❑ FIQ is the fastest followed by vectored IRQ with non-vectored IRQ
being the slowest.
❖ LPC2148 external interrupt inputs: 4
❖ Processor and on-chip user peripherals generate interrupts
❖ LPC2148 uses ARM PrimeCell (PL190) Vectored Interrupt
Controller for managing interrupts.
❖ When interrupt occurs,
➔ VIC identifies the source of interrupts
➔ Passes requests on interrupt request pins as per the configuration
➔ If more than one interrupt occurs at a time, VIC resolves priority
❖ 32 interrupt request inputs, LPC2148 uses 22 of 32 interrupts
Block diagram of the Vectored Interrupt Controller (VIC)
ARM PrimeCell Vectored Interrupt Controller (PL190)
SFRs
• VICIntSelect (R/W) 0 = IRQ, 1 = FIQ
• VICIntEnable (R/W) Enable Selective Interrupt Source
• VICIntEnClr (R/W) Disable Selective Interrupt Source
• VICIRQStatus (R)to know the status of enabled interrupt
• VICFIQStatus (R)to know the status of enabled FIQ
• VICSoftInt to trigger a software interrupt
• VICSoftIntClear to clear software interrupt
• VICVectCntl0 to VICVectCntl15 Assign interrupt source
• VICVectAddr0 to VICVectAddr15 Assign interrupt address
• VICVectAddr Holds the address of currently active interrupt
• VICDefVectAddr Holds the address of Non-Vectored ISR
Fast Interrupt reQuest (FIQ)
❖ FIQ requests have the highest priority.
❖ Any interrupt source may be assigned as the FIQ interrupt.
❖ The VIC interrupt select register has a unique bit for each
interrupt.
❖ However setting multiple bits in the Interrupt Select Register will
enable multiple FIQ interrupt sources.
❖ On entry the interrupt source can be determined by examining the
VIC FIQ Status register and the appropriate code executed.
❖ Once you have selected an FIQ source the interrupt can be
enabled in the VIC interrupt enable register.
❖ Once an FIQ interrupt is generated, the processor will change to
FIQ mode and vector to 0x0000001C, the FIQ vector.
Leaving An FIQ Interrupt
❖ Before you exit the ISR code you must make sure that any
interrupt status flags in the peripheral have been cleared.
❖ If this is not done you will get continuous interrupts until the flag
is cleared.
Vectored IRQ
❖ Vectored IRQs have the middle priority, but only 16 of the 32
requests can be assigned to this category.
❖ The VIC provides a programmable hardware lookup table which
delivers the address of the C function to run for a given interrupt
source.
❖ Any of the 32 requests can be assigned to any of the 16 vectored
IRQ slots, among which slot 0 has the highest priority and slot 15
has the lowest.
❖ Each slot contains a vector address register and a vector control
register.
❖ For a Vectored IRQ the VIC provides a hardware lookup table for
the address of each ISR. The interrupt priority of each peripheral
may also be controlled.
❖ The Vector Control Register contains two fields: a channel field
and an enable bit.
❖ The other register in the VIC slot is the Vector Address Register.
❖ As its name suggests, this register must be initialised with the
address of the appropriate C function to run when the interrupt
associated with the slot occurs.
Leaving An IRQ Interrupt
❖ The interrupt status flags are cleared in the peripheral which
generated the request.
❖ At the end of the interrupt you must do a dummy write to the
Vector Address Register.
❖ This signals the end of the interrupt to the VIC and any pending
IRQ interrupt will be asserted.
Non-Vectored Interrupts
❖ The VIC is capable of handling 16 peripherals as vectored
interrupts and at least one as an FIQ interrupt.
❖ If there are more than 17 interrupt sources on the chip, any extra
interrupts can be serviced as non-vectored interrupts.
❖ The non-vectored interrupt sources are served by a single ISR.
❖ The address of this ISR is stored in an additional vector address
register called the default vector address register.
Leaving A Non-Vectored IRQ Interrupt
❖ As with the vectored IRQ interrupt, you must clear the peripheral
flag and write to the vector address register.
Vectored Interrupt Controller (VIC)
If more than one request is assigned to FIQ, the VIC ORs the
requests to produce the FIQ signal to the ARM processor.
Bit allocation for various sources of interrupts
in VIC register
VICIRQStatus(RO): IRQ Status Register. This register reads out the state of
those interrupt requests that are enabled and classified as IRQ. It does not
differentiate between vectored and non-vectored IRQs. A bit read as 1
indicates a corresponding interrupt request being enabled, classified as
IRQ, and asserted.
VICFIQStatus(RO): FIQ Status Requests. This register reads out the state of
those interrupt requests that are enabled and classified as FIQ. If more
than one request is classified as FIQ, the FIQ service routine can read this
register to see which request(s) is (are) active.
VICRawIntr(RO): Raw Interrupt Status Register. This register reads out the
state of the 32 interrupt requests / software interrupts, regardless of
enabling or classification.
Each of these registers controls one of the 16 vectored IRQ slots. Slot 0
has the highest priority and slot 15 the lowest.
For example, the following two lines assign slot 0 to SPI0 IRQ interrupt
request(s) and slot 1 to TIMER0 IRQ interrupt request(s):
VICVectCntl0 = 0x20 | 10;
VICVectCntl1 = 0x20 | 4;
❖I2C Module
1. Features of I2C module
2. Applications
3. I2C Bus Configuration
4. Pin Description
5. I2C Registers
❖EEPROM interfacing with LPC2148
1. Algorithm for the Interfacing
3/26/2025 157
I2C-Bu
The I2C bus was designeds:by Philips in the early ’80s to allow easy
communication between components which reside on the same circuit
board. Philips Semiconductors migrated to NXP in 2006.
The name I2C translates into “Inter IC”. Sometimes the bus is called
IIC or I²C bus.
3/26/2025 158
I2C-Bu
s:
I2C is not only used on single boards but also to connect components
which are linked via cable. Simplicity and flexibility are key
characteristics that make this bus attractive to many applications.
3/26/2025 162
I2C-Bu
s:
The I2C block in LPC2148 and other LPC2100 series ARM7 MCUs can be
configured as either Master, Slave or both Master & Slave. It also features a
programmable clock which aids in using different transfer rates as required. The I2C
block in LPC214x supports speeds up to 400kHz.
Two wires of the I2C interface are SDA (serial data) and SCL (serial clock).
•SDA is Serial Data wire used for data transfer in between master and slave
•SCL is Serial Clock wire used for clock synchronization. Clock is provided
by the master
There are two types of data transfer possible on I2C interface depending on
Read/Write operation i.e.
Data transfer from Master Transmitter to Slave Receiver and
Data transfer from Slave Transmitter to Master Receiver
LPC2148 Interfacing with EEPROM using I2C
I2C Module
Features of I2C module
1. Standard I2C compliant bus interfaces that may be configured as Master, Slave,
or Master/Slave.
2. Arbitration between simultaneously transmitting masters without corruption of
serial data on the bus.
3. Programmable clock to allow adjustment of I2C transfer rates.
4. Serial clock synchronization allows devices with different bit rates to
communicate via one serial bus.
5. Serial clock synchronization can be used as a handshake mechanism to suspend
and resume serial transfer.
6. Bidirectional data transfer between masters and slaves.
7. The I2C bus may be used for test and diagnostic purposes.
3/26/2025 165
LPC2148 Interfacing with EEPROM using I2C
Applications
Interfaces to external I2C standard parts
1. Serial RAMs
2. LCDs
3. Tone generators
I2C Bus Configuration
3/26/2025 166
LPC2148 Interfacing with EEPROM using I2C
Pin Description
3/26/2025 167
LPC2148 Interfacing with EEPROM using I2C
Pin Description
LPC2148 I2C Pins
8 bits Explained
Bit Symbol Description
0-1 -- Reserved
Assert Acknowledge
2 AA
AA=1; request an acknowledge
I2C Serial Interrupt
3 SI
SI=1; indicate state change
STOP
4 STO
STO=1; sends stop condition
START
5 STA
STA=1; sends START condition
6 I2CEN I2CEN=1; I2C interface enable
7 - Reserved
3/26/2025 171
I2Cx Registers
1) I2C0CONSET (8 bit) :
I2C control set register: The bits in this register control the operation of the I2C interface. Writing a 1 to a bit of this
register causes the corresponding bit in the I2C control register(inside I2C block) to be set. Writing a 0 has no effect. This is
a Read-Write register.
3.Bit 3 – SI – I2C Interrupt Flag : This bit is set whenever the I2C state changes(Except for state code 0xF8). When SI is
set the Low Period of the serial clock is stretched which is also termed as clock stretching. When SCL is HIGH, its not
affected by the state of SI flag. SI must be reset using I2CONCLR register every time.
4.Bit 4 – STO – STOP Flag : When this bit is set to 1 the I2C interface will send a STOP condition.
5.Bit 5 – STA – START Flag : When this bit is set to 1 the I2C interface is forced to enter Master mode and send a START
Condition or send a Repeated START if its already in Master mode.
6.Bit 6 – I2EN – I2C interface Enable : This bit is used to Enabled or Disable the I2C interface. When set to 1 the I2C
interface is enabled and when set to 0 the I2C interface is disabled.
7.Bit 7 – Reserved.
I2Cx Registers
2) I2C0CONCLR (8 bit) – I2C control clear register. This register is used to clear bits in I2C0CONSET
register. Writing 0 no effect. The bit locations are same as that of I2C0CONSET register given above. Its a
Write only register.
3) I2C0STAT (8 bit) – This gives the current state of I2C interface in form of state codes. This is a read
only register.
4) I2C0DAT (8 bit) – This register contains the data that is to be transmitted or the latest received data.
Data in this register is always shifted from right to left i.e. the first bit to be transmitted is the MSB (bit 7),
and after a byte has been received, the first bit of received data is located at the MSB of I2C0DAT.
5) I20SCLH (16 bit) – This register is used to store the High time period of the SCL pulse.
6) I20SCLL (16 bit) – This register is used to store the Low time period of the SCL pulse.
7) I2C0ADR (8 bit) – I2C Slave Address register : Not applicable for master mode. Used to store the
address in slave mode.
I2Cx Registers
I2Cx Registers
LPC2148 Interfacing with EEPROM using I2C
Algorithm for the Interfacing
1. Start
2. Initialize I2C bus interface
PINSEL0=0X10400050; //Configure P0.11-SCL1 & P0.14-SD1
I2CSCLH=150;
I2CSCLL=150; //SET I2C frequency=[Pclk/(I2CSCLL+I2CSCH)]
3. Transmit the slave address(Page address, Page offset, No. of bytes)
4. Enable I2C bus interface
I2CCONSET=0X40;////I2CEN=1\
5. Master (LPC2148) will transmit START signal
I2CCONSET=0X20;//STA=1
3/26/2025 176
LPC2148 Interfacing with EEPROM using I2C
Algorithm for the Interfacing
3/26/2025 177
I2C operating modes
● When the START condition has been transmitted, the interrupt service
routine must load the slave address and the data direction bit to the I2C
Data Register (I2DAT), and then clear the SI bit.
● For master mode, the possible status codes are 0x40, 0x48, or 0x38.
● For slave mode, the possible status codes are 0x68, 0x78, or 0xB0.
The LSB of I2ADR is the general call bit. When this bit is set, the
general call address (0x00) is recognized.
Software must set values for the registers I2SCLH and I2SCLL to
select the appropriate data rate and duty cycle. I2SCLH defines the
number of PCLK cycles for the SCL high time, I2SCLL defines the
number of PCLK cycles for the SCL low time. The frequency is
determined by the following formula (fPCLK being the frequency of
PCLK)
Two-wire Serial
EEPROM
512K (65,536 x 8)
3/26/2025 187
On-chip DAC for waveform generation
DAC
▪10 bit digital to analog converter
▪ Power-down mode
Pin description
DAC Register (DACR)
http://www.ocfreaks.com/lpc2148-dac-programming-tutorial/
LPC2148-Interfacing-with-on-chip-DAC
•Features of DAC
•Digital to Analog Control Register (DACR)
∙Interfacing Diagram
∙Embedded C Program
3/26/2025 191
Features of DAC
3/26/2025 192
LPC2148-Interfacing-with-on-chip-DAC
3/26/2025 193
Introduction to DAC
Digital to Analog Converter (DAC) are mostly used to generate analog signals (e.g.
sine wave, triangular wave etc.) from digital values.
•LPC2148 has 10-bit DAC with resistor string architecture. It also works in Power
down mode.
•LPC2148 has Analog output pin (AOUT) on chip, where we can get digital value in
the form of Analog output voltage.
3/26/2025 196
DAC Pin Description
3/26/2025 197
Digital to Analog Control Register (DACR)
31-17 16 15-6 5-0
Reserved BIAS 10-bit Digital Value Reserved
Resolution :
•The resolution of a converter is the smallest change in voltage which may be produced at the
output (or input) of the converter. For example, an 8-bit D/A converter has 2^8-1=255 equal
intervals. Hence the smallest change in output voltage is(1/255) of the full scale output range.
•Resolution should be high as possible. It depends on the number of bits in the digital input applied
to DAC. Higher the number of bits, higher is the resolution.
•It can also be defined as the ratio of change in analog output voltage resulting from a change of 1
LSB at the digital input.
For n-bit DAC,
Accuracy :
•Absolute accuracy is the maximum deviation between the actual converter output and the
ideal converter output.
•Relative accuracy is the maximum deviation after gain and offset errors have been removed.
Settling time :
•Settling time represents the time it takes for the output to settle within a specified band ±(1/2)
LSB of its final value, after the change in digital input.
•It should be as small as possible.
ARM7 LPC2148 DAC example
As it can been seen, programming the DAC block is very straight forward. We
just need to select DAC function for P0.25 pin and feed a 10-bit value which
needs to be converted into its Analog form. Lets see a basic LPC2148 DAC
example. For most development boards VREF will be connected to VCC using
some form of noise isolation. In this DAC example, we will be changing the
output from 0V to VREF and then falling back to 0V in steps of 10ms. This DAC
program will basically output a sawtooth waveform. We will be using BIAS = 0
i.e. settling time of 1us. You can connect an Oscilloscope or a Multimeter
between P0.25 and GND to check the changing analog output. Since the output is
buffered you can drive an LED from AOUT but it won’t glow until it reaches its
forward bias voltage of around 1.7 Volts. So, keep this in mind when checking for
analog output using an LED.
3/26/2025 200
Programming Steps
•Now write 10-bit value (which we want to convert into analog form) in VALUE field of
DACR Register.
DAC register Configuration
Configure DAC register for generating with 3.3V VREF & Select 700
microseconds settling time.
1.0V,
2.1.65V,
3.3.3V
Formula:
AOUT= VREF * (10 bit Digital Value/Resolution)
Solution:
1.DACR = 0x00010000; //AOUT = 0V
2.DACR = 0x00018000; //AOUT = 1.65V
3.DACR = 0x0001FFC0; //AOUT = 3.3 V
Draw DAC interfacing diagram with LPC2148. Also write program
for triangular waveform generation
3/26/2025 202
DAC Interfacing Diagram
3/26/2025 203
Configuring internal DAC of LPC2148 for Generation of Triangular waveform
Embedded C Program
#include"LPC214x.h"
#define DACPinMask 1 << 19
#define DAC_DataMask 0x0000FFC0
#define DataShift 1<<6
void DACInit(void)
{
int i;
i = PINSEL1;
i = (i & 0xFFF3FFFF ); //Set P0.25 as AOUT Pin for analog output
PINSEL1 = (i | DACPinMask);
DACR = 1 << 16 ; //set the settling time to 2.5us and max current to 300uA
}
void delay(unsigned int time)
{
unsigned int i,j;
for(i = 0; i < time ;i++ )
{
for(j = 0; j < 10000 ; j++);
}
}
3/26/2025 204
Configuring internal DAC of LPC2148 for Generation of Triangular waveform
Embedded C Program
int main(void)
{
int i;
DACInit(); // initialsie the DAC interface
while(1)
{
for(i = 0 ; i < 1024 ;i++ ) // positive ramp of triangular waveform
{
DACR = ( DAC_DataMask & (i << DataShift));
delay(2);
}
for(i = 1023 ; i > 0 ;i-- ) //negative ramp of triangular waveform
{
DACR = ( DAC_DataMask & (i << DataShift));
delay(2);
}
}
return 0;
}
3/26/2025 205
DHT 11 Humidity & Temperature Sensor
DHT11 Temperature & Humidity Sensor features a temperature
& humidity with a calibrated digital signal output
DHT 11 Sensor
Technical Specifications
Interfacing with microcontroller
DHT11 Sensor
DHT11 is a single wire digital humidity and temperature sensor, which provides
humidity and temperature values serially.
It can measure relative humidity in percentage (20 to 90% RH) and temperature in
degree Celsius in the range of 0 to 50°C.
It has 4 pins of which 2 pins are used for supply, 1 is not used and the last one is used
for data.
The data pin is the only pin used for communication. Pulses of different TON and
TOFF are decoded as logic 1 or logic 0 or start pulse or end of the frame.
Overall Communication Process
•When MCU sends a start signal, DHT11 changes from the low-
power-consumption mode to the running-mode, waiting for MCU
completing the start signal.
•Without the start signal from MCU, DHT11 will not give the response
signal to MCU.
Example
Let’s see the example for Reading temperature and humidity from DHT11 sensor.
Here, the Data Pin of DHT11 is connected to P0.4 of LPC2148. UART0 is used for displaying
data on a serial monitor on a PC/laptop.
Programming Steps
•Initialize UART0
•Make the pin connected to the sensor data pin as an output pin and transmit a Start pulse.
•Make the pin connected to the sensor data pin as an input pin and receive the Response pulse
from the sensor.
•Once the response pulse is received, receive 40-bit data from the sensor.
•Display the received data on a serial terminal using UART0. In the case of checksum error, an
error indication is also displayed.
Interfacing of LPC2148 with servomotor
•A Servo Motor is a type of DC Motor (or AC Motor) that is used for precision linear or
angular positioning. A simple DC Servo Motor consists of a DC Motor, position sensor and a
feedback network that all combine and produce a very high accurate movement.
•Servo Motors aren’t used for continuous rotation like normal DC Motors. They are often
used in closed loop position control applications. One of the best application of the servo
motor is the robotic hand movement or tilt or pan movement of a CCTV camera.
•Even though stepper motors are also used for accurate position control, the main advantage
of servo motors over stepper motors is the power consumption. After achieving a desired
position, the servo motor stops consuming power.
•But in case of a stepper motor, after moving to a desired position, the stepper motor draws
power to lock itself to that position. Hence, servo motors have the advantage in low power
devices.
What is a Servo Motor?
A servo motor is a type of motor that can rotate with great precision.
Normally this type of motor consists of a control circuit that provides feedback on the
current position of the motor shaft, this feedback allows the servo motors to rotate
with great precision. If you want to rotate an object at some specific angles or
distance, then you use a servo motor
A Servo Motor is a combination of DC motor, position control system and gears. Servo motor’s rotation
is controlled by applying a PWM signal to it, width of the PWM signal decides the rotation angle and
direction of the motor. SG90 Servo Motor is one of the popular and cheapest one. SG90 is a 180
degree servo. So with this servo we can position the axis from 0-180 degrees:
•Operating Voltage: +5V
•Gear Type: Plastic
•Rotation Angle: 0 to 180 deg
•Weight: 9gm
•Torque: 2.5kg/cm
https://circuitdigest.com/article/servo-motor-working-and-basics
• Servo motor works on PWM (Pulse width modulation) principle, means
its angle of rotation is controlled by the duration of applied pulse to its
Control PIN.
For every 20 milliseconds Servo motor checks the pulse. So, adjust the pulse width of the
signal to rotate the motor’s shaft.
•1 ms (1 millisecond) pulse width for rotation of servo to 0 degree
•1.5ms pulse width for rotation to 90 degree (neutral position)
•2 ms pulse width for rotation of servo to 180 degree.
PWM working of LPC2148
Understanding the Program
There are two main aspects of the program for Servo Motor interfacing with LPC2148: Generation of Clock
signal using PLL Module and Generation of PWM signal using PWM generator. First, we see the generation
of clock using PLL. The system clock CCLK and peripheral clock PCLK are set to user preferred values
using the on – chip PLL of the LPC2148. The limit of the clock signal frequency for LPC2148 MCU is 60
MHz So, using the following lines of code in the program, we can generate a 60 MHz CCLK and a 60 MHz
PCLK. A detailed information and tutorial about PLL in LPC2148 can be found here. First, we need to
enable the PLL0 module and set the multiplier and divider values. For that, the following commands can be
used.
PLL0CON = 0x01;
PLL0CFG = 0x24;
Next step is to lock these multiplier and divider values using a feed sequence.
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
Now wait for the PLL to lock to the values and connect the PLL module.
while (! (PLL0STAT & 0x00000400));
PLL0CON = 0x03;
Once again, lock the values with feed sequence and also enable the PCLK to same frequency as CCLK.
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
VPBDIV = 0x01;
With these instructions, the CCLK and PCLK are set at 60 MHz using the PLL0 module.
Next step is to initialize the PWM Module and generate PWM signal
PWMPCR = 0x0; //Selecting Single Edge PWM (it is selected by default)
PWMPR = PWMPRESCALE-1; // PWMPRESCALE=60 for 1 micro-second resolution
PWMMR0 = 10000; // Duration of the period is set to 10 ms
PWMMR5 = 2500; // Pulse duration is set to 2.5 ms
PWMMCR = (1<<1); // PWMTC is reset on PWMMR0 match
PWMLER = (1<<5) | (1<<0); // update MR0 and MR5
PWMPCR |= (1<<13); // PWM output is enabled
PWMTCR = (1<<1) ; //Reset PWM TC & PR
PWMTCR = (1<<0) | (1<<3); // Finally, enable counters and PWM Mode
With the above mentioned commands, the PWM5 is set and generates PWM signal. Final step
is to control the Pulse duration with the help of buttons.
If button connected to P0.15 is pushed, the duty cycle should be 50%. So, the following code
will do that.
if( !((IO0PIN) & (1<<15)) ) // Check P0.15
{
PWMMR5 = 5000; //T-ON=50%
PWMLER = (1<<5); //Update Latch Enable bit for PWMMR5
#include
<lpc214x.h>
#define PWMPRESCALE 60
int main(void)
{
PLL0CON=0x01;
PLL0CFG=0x24;
PLL0FEED=0xaa;
PLL0FEED=0x55;
while(!(PLL0STAT & 0x00000400));
PLL0CON=0x03;
PLL0FEED=0xaa;
PLL0FEED=0x55;
VPBDIV=0x01;
PINSEL1=0x00000400;
PWMPCR = 0x0;
PWMPR = PWMPRESCALE-1;
PWMMR0 = 10000;
PWMMR5 = 2500;
PWMMCR = (1<<1);
PWMLER = (1<<5) | (1<<0);
PWMPCR |= (1<<13);
PWMTCR = (1<<1) ;
PWMTCR = (1<<0) | (1<<3);