Thank you very much, this was very helpful for me. I will code everything in C, but I am waiting for sensor now (I've ordered it on ebay). Unfortunately, I didn't find anything on this forum with search string "DHT22" or "AM2302" or "RHT03". Google didn't find it neither, nothing else than Arduino and C++. But I will help my self with your assembly code and for that, thank you again.
Ok, I got the sensor, and I wrote basic routines for it. After I send a start signal to sensor, I get low signal response from it and then sensor pulls high, after that, it times out (for more than 80us). I don't know why. This asm, you sent me, it's not working, becouse It does not do the sequence as it is in datasheet (page 4).
Should I wait for more than 80us for sensor to switch state?
uint8_t DHTStart(void)
{
DHT_PORT_IZHOD;
DHT_LOW;
_delay_ms(25);
DHT_HIGH;
_delay_us(40);
DHT_PORT_VHOD;
_delay_us(2);
/*Najprej pošlje pozitiven signal za določen čas, nato negativnega. Če med tem poteče timer, ni bilo odziva*/
TCNT0 = 206;
SREG |= _BV(7);
while(!DATA_GET && !Timflag);
if(Timflag){
SREG &= ~(_BV(7));
Timflag = 0;
return 0;
} //timeout po 80us negativnega signala
TCNT0 = 206;
while(DATA_GET && !Timflag);
if(Timflag){
SREG &= ~(_BV(7));
Timflag = 0;
return 0;
} //timeout po 80us pozitivnega signala
return 1;
}
Hi:
Looking at exactly the same Thermometer/Sensor(RHT03) and saw your sample assembly code. I'm using an 18F458. What is the "D1" in your code for? Thanks.
You are very generous to do this! Thank you! I will be testing this tomorrow after class and will let you know how it goes. I have it attached to the breadboard and would like to see what the results are in the registers! I saw something on MaxDetect that says the following is needed for conversion:
"DATA=16 bits RH data+16 bits Temperature data+8 bits check-sum
Example: MCU has received 40 bits data from RHT03 as
0000 0010 1000 1100 0000 0001 0101 1111 1110 1110
16 bits RH data 16 bits T data check sum
Here we convert 16 bits RH data from binary system to decimal system,
0000 0010 1000 1100 → 652
Binary system Decimal system
RH=652/10=65.2%RH
Here we convert 16 bits T data from binary system to decimal system,
0000 0001 0101 1111 → 351
Binary system Decimal system
T=351/10=35.1℃
When highest bit of temperature is 1, it means the temperature is below 0 degree Celsius.
Example: 1000 0000 0110 0101, T= minus 10.1℃
16 bits T data
Sum=0000 0010+1000 1100+0000 0001+0101 1111=1110 1110
Check-sum=the last 8 bits of Sum=1110 1110"
Hi:
Thank you for the advice. I am using a 10mhz oscillator. I got the code to compile and run. I am having trouble(since I'm new with Assembly) to getting values from the device to the display. I had to divert attention to a Java project, which I just progressed on today. Now I can focus on this again for the weekend. I will update you with what I can get running. Thank you for your motivation, suggestions and sample code. I am using the "PIC Microcontroller and Embedded Systems" book from Mazidi, Mckinlay and Causey. More later.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?