Documente Academic
Documente Profesional
Documente Cultură
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
COURSE CO-ORDINATOR
Ms. DIVYA G
Assistant Professor, Dept. of ECE
Nitte Meenakshi Institute of Technology
Bangalore – 64
ACKNOWLEDGEMENT
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.
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:
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.