Part Number: TM4C123GH6PM
Tool/software: Code Composer Studio
Hello everybody,
I try to connect temperature / humidity sensor DHT11 with TM4C123GH6PM. I had success - temperature and humidity were ok. Suddenly , when I try to read data again some problem occur. Please dont say look at connection because I checked many time. Problem occur because sensor give High or 1 all time after 0. Can someone who have DHT11 try my code. And 1 more thing, I use 10k or 5k pull up resistor on data line.
And one more question : Why code cant be builded when I use <math.h> ?
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
//#include <math.h>
#include "hw_memmap.h"
#include "hw_types.h"
#include "hw_gpio.h"
#include "debug.h"
#include "rom.h"
#include "sysctl.h"
#include "gpio.h"
#include "rom_map.h"
#include "abi_prefix.h"
#include "crc_defines.h"
#include "rtos_bindings.h"
#include "fpu.h"
#include "adc.h"
#include "aes.h"
#include "arm_acle.h"
#include "assert.h"
#include "can.h"
#include "comp.h"
#include "complex.h"
#include "cpu.h"
#include "cpy_tbl.h"
#include "crc.h"
#include "ctype.h"
#include "des.h"
#include "etsi.h"
#include "interrupt.h"
#include "inttypes.h"
#include "lcd.h"
#include "iso646.h"
#include "limits.h"
#include "lowlev.h"
#include "locale.h"
#include "mpu.h"
#include "onewire.h"
#include "pprof.h"
#include "pin_map.h"
#include "stdio.h"
#include "stdnoreturn.h"
#include "stdlib.h"
#include "sysexc.h"
#include "signal.h"
#include "shamd5.h"
#include "tm4c123gh6pm.h"
#include "i2c.h"
#include "time.h"
#include "timer.h"
#include "pwm.h"
uint32_t variable[40];
unsigned long Humidity, HumidityDecimalPart, Temperature, TemperatureDecimalPart, Validation;
/************************ PA3 connect to data pin of DHT11 ************************************/
/************************ Put 10k pull up resistor between data line and Vcc ******************/
/************************ Temperature accuracy between +-2C and +-1C **************************/
/************************ Temperature measurement range 0 - 50C *******************************/
/************************ Humidity accuracy between +-4% and +-5% *****************************/
/************************ Humidity measurement range 20 - 90% *********************************/
unsigned long ConversionBinaryToDecimal(int startBit){
int i = 0;
unsigned long convertedNum = 0;
for(i = startBit; i <= (startBit + 7); i++){
convertedNum = convertedNum + variable[i] * pow(2, i);
}
return convertedNum;
}
void Interrupt_Function_GPIO_PORTF(void){
GPIOIntClear(GPIO_PORTF_BASE, GPIO_INT_PIN_0);
GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, ~GPIO_PIN_3); // low voltage on PA3
SysCtlDelay(302000); // 18.12mS delay
GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_PIN_3); // high voltage on PA3
SysCtlDelay(500); // 500 = 30uS
GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_3); // input pins PF0 and PF4
GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // pull up resistor , 2mA max
while(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_3) == 0){};
while(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_3) == GPIO_PIN_3){};
int i;
for(i = 0; i < 40; i++){
while(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_3) == 0){};
SysCtlDelay(450); // 45 uS = 750
if(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_3) == GPIO_PIN_3){
variable[i] = 1;
while(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_3) == 8){};
}else{
variable[i] = 0;
}
}
//SysCtlDelay(50000000); // 1sec delay
/* Humidity = ConversionBinaryToDecimal(0);
HumidityDecimalPart = ConversionBinaryToDecimal(8);
Temperature = ConversionBinaryToDecimal(16);
TemperatureDecimalPart = ConversionBinaryToDecimal(24);
Validation = ConversionBinaryToDecimal(32);
*/
}
void main(void){
/**************************** CLOCK and ENABLE PERIPHERALS *********************************/
SysCtlClockSet(SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ | SYSCTL_SYSDIV_4); // clock set 50MHz
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // enable portF
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // enable portA
/*******************************************************************************************/
/**************************** GPIO CONFIG **************************************************/
GPIO_PORTF_LOCK_R = GPIO_LOCK_KEY;
GPIO_PORTF_CR_R = 0x01;
GPIO_PORTA_LOCK_R = GPIO_LOCK_KEY;
GPIO_PORTA_CR_R = 0x08;
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0); // input pins PF0
GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // pull up resistor , 2mA max
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_3); // output pin PA3
GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_PIN_3); // high voltage on PA3
/*******************************************************************************************/
/**************************** GPIO INTERRUPT CONFIG ****************************************/
IntMasterEnable();
IntEnable(INT_GPIOF);
IntPrioritySet(INT_GPIOF, 4);
GPIOIntEnable(GPIO_PORTF_BASE, GPIO_INT_PIN_0);
GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_FALLING_EDGE);
IntRegister(INT_GPIOF, Interrupt_Function_GPIO_PORTF);
/*******************************************************************************************/
while(1){
}
}
