This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Interfacing DHT11 with nRF52 DK

Hello!

I'm trying to interface the DHT11 with my DK. I'm coming from Arduino where all I had to do is to drop some library and instantiate an object. Here with the nRF52 (832) things are different. I'm using Keil and the nRF52832 is Arm Cortex M4F but I'm using the SoftDevice still to interface it as I understand it. I don't know if there are libraries of stuff like this like with Arduino, if so please point me in the right direction. 

For now I'm trying to get thru the datasheet like an real engineer and not some Arduino script kiddi :-).

Datasheet @ Mouser

As I understand it I have to "transmit" low to the DHT for >18ms, then set it to read and expect 40 bits (5 bytes). The bytes are for humidity (2 bytes), temperature (2 bytes) and checksum (sum of bytes).

MCU transmission:

void DHTInit()
{
	nrf_gpio_cfg_input(DHT11_PIN, NRF_GPIO_PIN_PULLUP);

	SEGGER_RTT_WriteString(0, "DHT init complete\n");
}

Then I receive:

uint8_t DHTReceiveData()
{	
	nrf_gpio_pin_set(DHT11_PIN);
	
	nrf_delay_ms(250);
	
	nrf_gpio_cfg_output(DHT11_PIN);
	
	nrf_gpio_pin_clear(DHT11_PIN);
	
	nrf_delay_ms(20);
	
	nrf_gpio_pin_set(DHT11_PIN);
	
	nrf_delay_us(40);
	
	nrf_gpio_cfg_input(DHT11_PIN, NRF_GPIO_PIN_PULLUP);
	
	nrf_delay_us(10);
	
	//=====================
	
	uint32_t value = nrf_gpio_pin_read(DHT11_PIN);
	
	uint8_t byte_0 = (value >> 24) & 0xFF;
	uint8_t byte_1 = (value >> 16) & 0xFF;
	uint8_t byte_2 = (value >> 8) & 0xFF;
	uint8_t byte_3 = (value) & 0xFF;
	
	SEGGER_RTT_WriteString(0, "Value: ");
	SEGGER_RTT_WriteString(0, (char*)&byte_2);
	SEGGER_RTT_WriteString(0, "\n");
	
	return byte_2;
}

One issue is the nrf_gpio_pin_read, it reads uint32_t where the logic needs uint8_t. I don't know how to get around this issue. I guess there are other issues as well :-/. The above code is my (faulty) adaption of Adafruits DHT library found here https://github.com/adafruit/DHT-sensor-library/blob/master/DHT.cpp (begin & read functions)

Related