はっくはっくキッチン
Hack Hack Kitchen

am2302.asm

 2021/12/25

Subroutines for AM2303 (aka DHT22) relative humidity (RH) and temperature sensor This code is a part of pAVRlib.

Requirement

How to use

Define F_CPU (frequency of CPU), AM_DDR, AM_PORT, AM_PIN and AM_SDA before you call AM2302_READ.

For example, to use PB0 as SDA for AM2302:

.equ F_CPU	= 1000000	; 1 MHz

.equ AM_DDR	= DDRB
.equ AM_PORT	= PORTB
.equ AM_PIN	= PINB
.equ AM_SDA	= 0

Note that F_CPU must be > 100000 (100 kHz) (theoretically. But practically > 300 kHz ?). (This module was tested only at 1 MHz.)

Subroutine

long AM2302_READ() (in: (none), out: r25-r22 (HumH, HumL, TmpH, TmpL))

reads data from AM2302. This returns r25:r24:r23:r22 = ff:ff:ff:ff ($-1$ as long) if parity error occured. This returns also a raw parity value in r21 if the program is assembled with AM2303_DEBUG.

Examples

../examples/am2302-test.asm

This program reads data from AM2302 and show the data via USART like this:

$ dterm /dev/ttyUSB0 4800
# Hallo AM2302
59.6 %RH, 24.0 C [02 54 00 F0 46] (77 33, 62 00)
59.7 %RH, 23.9 C [02 55 00 EF 46] (77 66, 61 CC)
59.8 %RH, 23.9 C [02 56 00 EF 47] (77 99, 61 CC)
 :
 :

where:

  • values in […]: raw data from AM2302

  • values in (…): converted humidity and temperature for CCS811

To compile this file, the following files are required (These files are parts of the pAVRlib).

See also: examples/README.org

../examples-C/am2302-test.c

The test program for am2302.asm (C version).

To compile this file, the following files are required (These files are parts of the pAVRlib).

See also: examples-C/README.org