Part Number:TM4C123GH6PM
Tool/software: Code Composer Studio
Hi,
I'm trying to setup the connection between my TM4C123GH6PM LaunchPad and DHT11 temperature sensor using CCS. I'm done sending Start signal from my board yet struggling in the receiving phase since I always got returned a high level pulse when it was supposed to be an 80us low pulse followed by an 80us high pulse. My code is based on the library given by the sensor's manufacturer: https://github.com/adafruit/DHT-sensor-library. The info about the changing pulses is included below. Please help and thank you for your time ! Here's my developing code:
/**
* main.c
*/
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
//#include "DHT.h"
#include "DelayTimer.h"
#include "debug.h"
#include "inc/hw_ints.h"
#include "inc/hw_timer.h"
#include "inc/hw_types.h"
#include "inc/hw_nvic.h"
#include "inc/hw_memmap.h"
#include "driverlib/rom.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"
#include "driverlib/uart.h"
#include "driverlib/gpio.h"
#include "uartstdio.h"
uint32_t expectPulse(bool level);
int main(void)
{
//initiate system clock
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
//initiate port D peripheral
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
//------------------------------------------------------------------------------
//Enable peripherals GPIOA and UART0
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//Configure so that pin A0 works as UART0 Rx, A1 works as UART0 Tx
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
//Define which pins of GPIOA is used as UART
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//Set the baud clock source of UART0 to be precision internal OSC
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
//The function declaration is in uartstdio.c. In this case we pass the baudrate of 115200 and the OSC frequency of 16MHz to UART0
UARTStdioConfig(0, 115200, 16000000);
//-----------------------------------------------------------------------------------
timerInit();
uint32_t cycles[80],i;
uint8_t data[5];
//reset data
data[0] = data[1] = data[2] = data[3] = data[4] = 0;
DBG ("DHT11 example\n");
while(1){
ROM_GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_0);
//ROM_GPIOPadConfigSet(GPIO_PORTD_BASE,GPIO_PIN_0,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
ROM_GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_0,1);
delay(250);
ROM_GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_0,0);
delay(20);
ROM_GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_0,1);
delayMicroseconds(40);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);
delayMicroseconds(10);
if(!expectPulse(false)){
DBG("Timeout waiting for start signal low pulse\n");
}
if(!expectPulse(true)){
DBG("Timeout waiting for start signal high pulse\n");
}
}
return 0;
}
//-----------------------------------------------------
uint32_t expectPulse(bool level){
uint32_t count=0;
while(ROM_GPIOPinRead(GPIO_PORTD_BASE,GPIO_PIN_0)==level){
if (count++>=1000){
return 0;
}
}
return count;
}
(Please visit the site to view this file)