Sunteți pe pagina 1din 12

NITTE MEENAKSHI INSTITUTE OF

TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)
AFFILIATED TO VISVESVARYA TECHNOLOGICAL UNIVERSITY, BELGAUM
APPROVED BY AICTE & GOVT. OF KARNAKATA
YELAHANKA, BANGALORE – 560064

ADVANCED MICROCONTROLLERS
(Mini – Project)

Report on
Interfacing DHT11 & DHT22 Sensor with
LPC2148
(USING ARM CORTEX M3)
Submitted by

NIKHIL ECE 1NT16EC092


KUMAR G
SAICHARAN T ECE 1NT16EC131
PREETHAM ECE 1NT16EC108
MOHAMMED ECE 1NT16EC082
AYUB MODI

COURSE CO-ORDINATOR
Ms. DIVYA G
Assistant Professor, Dept. of ECE
Nitte Meenakshi Institute of Technology
Bangalore – 64

This is to certify that the Mini-Project entitled


“Interfacing DHT11 & DHT22 Sensor with
LPC2148
(USING ARM CORTEX M3)”
Is the bonafied work
of nikhil(1NTEC092),saicharan(1NT16EC131),Ayub (1NT16EC082)
and preetham(1NT16EC108) for the Course on “advanced
microcontrollers”
during the Academic Year 2018-19.

SIGNATURE OF THE COURSE CO-ORDINATOR

ACKNOWLEDGEMENT

Nothing is envisaged without the help guidance of an experienced


person respect in the field of concert subject. Through the benefits
achieved from them can never be adequately valued, we would like
to express hearty gratitude towards them.
Firstly we express our sincere gratitude to Dr. N R SHETTY,
Advisor, NMIT and Dr. H C NAGARAJ, Principal, NMIT, and
Head of Department of ECE, Mrs. SANDHYA, for providing the
good infrastructure and support at NMIT We would like to take this
opportunity to thank Ms. DIVYA.G, Assistant Professor ECE for
her valuable suggestions and support throughout the course of
advanced microcontrollers.
History of arm and arm architecture
ARM, previously Advanced RISC Machine, originally Acorn RISC Machine, is
a family of reduced instruction set computing (RISC) architectures for computer
processors, configured for various environments. Arm Holdings develops the
architecture and licenses it to other companies, who design their own products that
implement one of those architectures—including systems-on-chips (SoC)
and systems-on-modules (SoM) that incorporate memory, interfaces, radios, etc. It
also designs cores that implement this instruction set and licenses these designs to
a number of companies that incorporate those core designs into their own products.
Processors that have a RISC architecture typically require fewer transistors than
those with a complex instruction set computing (CISC) architecture (such as
the x86 processors found in most personal computers), which improves cost, power
consumption, and heat dissipation. These characteristics are desirable for light,
portable, battery-powered devices—including smartphones, laptops and tablet
computers, and other embedded systems. supercomputers, which consume large
amounts of electricity, ARM could also be a power-efficient solution.
ARM Holdings periodically releases updates to the architecture. Architecture
versions ARMv3 to ARMv7 support 32-bitaddress space (pre-ARMv3 chips, made
before ARM Holdings was formed, as used in the Acorn Archimedes, had 26-bit
address space) and 32-bit arithmetic; most architectures have 32-bit fixed-length
instructions. The Thumb version supports a variable-length instruction set that
provides both 32- and 16-bit instructions for improved code density. Some older
cores can also provide hardware execution of Java bytecodes. Released in 2011,
the ARMv8-A architecture added support for a 64-bit address space and 64-bit
arithmetic with its new 32-bit fixed-length instruction set.
With over 100 billion ARM processors produced as of 2017, ARM is the most
widely used instruction set architecture and the instruction set architecture
produced in the largest quantity cores, older "classic" cores, and
specialized SecurCore cores variants are available for each of these to include or
exclude optional capabilities.
32-bit architectures (Cortex)

Version ARMv8-R, ARMv8-M,


ARMv7-A, ARMv7-R,
ARMv7E-M, ARMv7-M,
ARMv6-M
Encoding 32-bit except Thumb-2
extensions use mixed 16-
and 32-bit instructions.
Endianness Bi (little as default);
Cortex-M is fixed and can't
change on the fly.
Extensions Thumb-2, NEON, Jazelle,
DSP, Saturated, FPv4-SP,
FPv5
Registers
General purpose 15× 32-bit integer
registers; R15 is PC (26-bit
addressing in older), R14 is
link register.
Floating point Up to 32× 64-bit
registers,[2]SIMD/floating-point
(optional)

32-bit architectures (legacy)


Version ARMv6, ARMv5,
ARMv4T, ARMv3,
ARMv2
Encoding 32-bit except Thumb
extension uses mixed 16-
and 32-bit instructions.
Endianness Bi (little as default) in
ARMv3 and above
Extensions Thumb, Jazelle
Registers
General purpose 15× 32-bit integer
registers; R15 is PC (26-bit
addressing in older), R14 is
link register.
ARM Cortex-M3
ARM's Flagship Cortex-M Class Processor
The ARM Cortex-M3 processor offers superior efficiency and flexibility and is
specifically developed for response and power sensitive applications. The EFM3
32-bit MCUs use the Cortex-M3's low power and high performance abilities in
combination with Silicon Labs' unique low power peripherals to create a superior
low power embedded systems platform.
 Low Power
 32-bit Cortex-M3 designed for low power operation
 High power efficiency with Thumb®-2 instruction set
 Small core footprint with integrated power mode support
 High Performance
 Cortex-M3 delivering 1.25 DMIPS/MHz
 Separate data and instruction bus
 High code density and performance with Thumb-2 instruction set
 Excellent clock per instruction ratio
 Nested Vectored Interrupt Controller (NVIC) for outstanding interrupt
handling
 Superior math capability

Thumb-2 Instruction Set Architecture (ISA)


Cortex-M3 supports 16- and 32-bit instructions available in the Thumb-2
instruction set. Both can be mixed without extra complexity and without reducing
the Cortex-M3 performance. Hardware divide instructions and a number of
multiply instructions give EFM32 users high data-crunching throughput.
3-stage Pipeline Core Based on Harvard Architecture
The ARM Cortex-M3 3-stage pipeline includes instruction fetch, instruction
decode and instruction execution. Cortex-M3 also has separate buses for
instructions and data. The Harvard architecture reduces bottlenecks common to
shared data- and instruction buses. Quickly Servicing Critical Tasks and Interrupts
From the low energy modes, EFM32's Cortex-M3 is active within 2 µs and
delivers 1.25 DMIPS/MHz on the Dhrystone 2.1 Benchmark. The NVIC is an
integral part of the Cortex-M3 processor and ensures outstanding interrupt
handling abilities. It is possible configure up to 240 physical interrupts with 1-256
levels of priority, and Non-Maskable Interrupts further increase interrupt handling.
For embedded systems this enhanced determinism makes it possible to handle
critical tasks in a known number of cycles.
Programming on cortex m3
Objectives

This module is framed to set the required background in embedded system


concepts and ‘C’ language for the rest of the modules. It aims at familiarizing the
students in embedded concepts and programming in ‘C’. This module covers the
advanced topics in ‘C’ such as Memory management, Pointers, Data structures
which are of high relevance in embedded software is considered in depth. This
module makes use of KEIL C Compiler along with ARM Cortex Microcontrollers.
This module covers the architecture of the popular 32-bit bit Microcontroller such
as ARM. The ARM Cortex processor is the industry-leading 32-bit processor for
highly deterministic real-time applications, specifically developed to enable
partners to develop high-performance low-cost platforms for a broad range of
devices including microcontrollers, automotive body systems, industrial control
systems and wireless networking and sensors.

The importance of ‘C’ and Embedded C


Introduction to ‘C’ programming, Storage Classes, Data Types, Controlling
program flow, Arrays, Functions, Memory Management, Pointers, Arrays and
Pointers, Pointer to Functions and advanced topics on Pointers, Structures and
Unions, Data Structures, Linked List, Stacks, Queues, Conditional Compilation,
Preprocessor directives, File operations, Variable arguments in Functions,
Command line arguments, bitwise operations, Typecasting.
Introduction to hardware programming using
LPC2148
Uploading a .hex file using flash magic
.Hex Using Flash Magic

You need a USB to Serial (UART) converter in order to get this working. The neat
thing about the NXP controllers is, they come with a UART bootloader from the
factory.

Now open the flash magic software and follow the below steps.
1. Select the IC from Select Menu.
2. Select the COM Port. Check the device manager for detected Com port.
3. Select Baud rate from 9600-115200
4. Select None Isp Option.
5. Oscillator Freq 12.000000(12Mhz).
6. Check the Erase blocks used by Hex file option
7. Browse and Select the hex file.
8. Check the Verify After Programming Option.
9. If DTR and RTS are used then go to Options->Advanced Options->
Hardware Config and select the Use DTR and RTS Option.
10.Hit the Start Button to flash the hex file.
11.Once the hex file is flashed, Reset the board. Now the controller should run
your application code.

Introduction to DHT 11 sensor and interfacing with


LPC2148

Interfacing DHT11 & DHT22 Sensor with LPC2148

In this tutorial we learn how to interface DHT11 and DHT22 Humidity and
Temperature sensor with ARM Cortex-M3 LPC2148 microcontroller. I had
discussed basics of DHT11/DHT22 interfacing in my previous tutorial. Please go
through it if you are new to DHTxx Humidity and Temperature sensors.
A quick recap of the communication process:
DHT11/DHT22 Data format:

Now, lets have a look at steps we need to implement for Programming


DTH11/DHT22. Since only one DATA line(PIN) is used, we will use the same
GPIO PIN first as OUTPUT to send START condition and then as INPUT to
Receive data.
Steps required for DHT11/DHT22 Interfacing:

1. Configure PIN to be used to communication as OUTPUT.


2. Set the PIN O/P to LOW and wait for 18 milli-seconds.
3. Configure the PIN as INPUT. The pull-up resistor will Pull the bus to
HIGH.
4. Wait until DHT responds and pulls the line to LOW after around 40 micro-
seconds or else exit as timeout error.
5. Next, check for 80us LOW followed by 80us HIGH from DHT. This
condition denotes that DHT is ready to send data next.
6. Now, check for 50us LOW followed by 26us to 28us HIGH denoting data
bit ‘0’ or 50us LOW followed 70us HIGH denoting data bit ‘1’. Store the
interpreted bit in an array. Repeat this for each of 40 bits.
7. Extract the data bytes from array to record or display it. Optionally the
checksum can be used to verify data integrity.
8. Wait for at least 1 second before starting again to fetch new data.
Program for Interfacing DHT11/DHT22 with ARM LPC1768/LCP1769:
In this example we will use PIN P0.0 (marked as P9 on mbed board) for
communication with DHT11 sensor. For DHT22 you just need to make a small
change in code to display the decimal part. I leave that to the reader. If you are
using the bare 4 pin sensor than make sure that DATA pin is pulled up using 4.7K
or 10K resistor. If you are using PCB mounted sensor which has 3 pins then
external pullup resistor is not required since it is already present on the PCB.
Timer0 module is used for generating delay and measuring timing of responses
given by DHTxx. You can go through LPC1768 timer tutorial for reference.
We will also use UART0 to send data back to PC and display it using software
terminal. printf() has been targeted such that its output gets redirected to UART0.
Checkout my tutorial on how to retarget printf() in keil and LPC1768 UART
tutorial for more. The schematic for connections between DHT11 and LPC214x is
as given below:

Before going through to source code, first lets go through some the
functions used:
 Start Timer0() – Resets counter and Enables Timer0 block.
 Un-signed int stopTimer0() – Disables counting and returns value in T0TC.
 checkResponse(…) – Used to check the response from DHTxx. It has 3
parameters viz. unsigned int waitTimeUS, unsigned int margin, bool
pinValue. waitTimeUS is simply the expected wait time in micro-seconds.
Margin is additional timing error or offset we can account for, since the
sensor might have intrinsic timing offets. pinValue is the current expected
state of pin which it must hold until the given waitTime.
 char getDataBit() – This checks the pulses for a ‘0’ or a ‘1’ and returns the
value accordingly. It will return 2 in case of an error.
 printError(const char * str) – Prints error message and halts program
execution by entering infinite while loop. You must reset board in this
situation or you can extend the code to handle errors on the fly.

S-ar putea să vă placă și