This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GH6PM: TM4C123GH6PM

Part Number: TM4C123GH6PM


Hi, I'm working on DHT11 humidity and temperature sensor. According to the datasheet, I have maintained all the protocols for the sensor to run in stable mode. However, my code does goes through my 4th while loop, that I have used to check if there's high data. The following is the loop that goes infinitely. 

while((GPIO_PORTC_DATA_R & 0x10) == High_Out) // Iterates until data line is high
{}

I have pasted the code below, I know how to retrieve data bit by bit, but I cannot go through this part. Any help wiill be appreciated.

Datasheet : https://akizukidenshi.com/download/ds/aosong/DHT11.pdf

#include <TM4C123GH6PM.h>
#include <stdio.h>
#include <stdint.h>

#define SYSCTL_RCGCGPIO_R (*((volatile unsigned long *)0x400FE608))

#define GPIO_PORTC_DEN_R (*((volatile unsigned long *)0x4000651C))
#define GPIO_PORTC_DIR_R (*((volatile unsigned long *)0x40006400))
#define GPIO_PORTC_DATA_R (*((volatile unsigned long *)0x400063FC))



void Delay(unsigned long int period);
int Binary2Decimal(int Bit_L, int Bit_H, unsigned int Binary[]);
void UART0_Init(void);
void UartWrite(char *pstr);
unsigned char Receiver(void);
void Transmitter(unsigned int data);
void Transmitter1(unsigned char data);
void PLL_Init(void);


#define Clock_GPIO_C 0x04
#define DIR_PIN4_In ~0x10
#define DIR_PIN4_Out 0x10
#define High_In 0x10
#define Low_In ~0x10
#define High_Out 0x10
#define Low_Out 0x00
#define DEN_ENABLE_C4 0x10

int main(void){
int i=0;
unsigned int Data[40];
int Temp_16, Temp_High, Temp_Low; // Varaibles for Temperature
int RH_16, RH_High, RH_Low; // Variables for Relative Humidity
int Check_Sum, temp, sum; // Variables fro Parity Checking
int x,y,z;
SYSCTL_RCGCGPIO_R |= Clock_GPIO_C; // Clock for Port C
Delay(100); // Delay to make Clock Smooth
GPIO_PORTC_DEN_R |= DEN_ENABLE_C4; // Set Pin C4 as Digital
PLL_Init(); 
UART0_Init();

while(1){ // For taking and displaying values of Sensors again and gain (infinitely)
while(1) // Iterates untill temperature and humidity values are true
{
GPIO_PORTC_DIR_R |= DIR_PIN4_Out; // Set Pin C4 as output
GPIO_PORTC_DATA_R &= Low_In; // Set data line low for 1ms to awake the sensor
Delay(100000);
GPIO_PORTC_DATA_R |= High_In; // Set data line high for 30us
Delay(100000);
GPIO_PORTC_DIR_R &= DIR_PIN4_In; // Set Pin C4 as Input

while((GPIO_PORTC_DATA_R & 0x10) == Low_Out) // Iterates untill data line is low
{}
while((GPIO_PORTC_DATA_R & 0x10) == High_Out) // Iterates untill data line is high
{}



void Delay(unsigned long int period)
{
int i=0;
for(i=0;i<12*(period/10);i++);
}

int Binary2Decimal(int Bit_L, int Bit_H, unsigned int Binary[])
{
int temp=0,i;
for(i = Bit_L;i<Bit_H;i++)
temp += Binary[i] * (1<<((Bit_H-1)-i));
return temp;
}

void UART0_Init(void)
{
SYSCTL->RCGCUART |= 0x00000001; //UART0 
SYSCTL->RCGCGPIO |= 0x00000001; //PORTA CLOCK ENABLE
UART0->CTL &= ~0x00000001; //UART0 DISABLE
UART0->IBRD = 43; //BAUD INTEGER
UART0->FBRD = 26; //BAUD FLOATING
UART0->LCRH = 0x00000070; //ENABLE FEN & WLEN
UART0->CTL |= 0x00000001; //UART ENABLE;

GPIOA->AFSEL |= 0x03; // OTHER ALTERNATIVE FUNCTION AT PORTA 0-1
GPIOA->DEN |= 0x03; // PORTA0-1 OUTPUT
GPIOA->PCTL = (GPIOA->PCTL&0xFFFFFF00)+0x00000011; //GPIO PORTA 0-1
GPIOA->AMSEL &= ~0x03; //ANALOG DISABLE
}
void UartWrite(char *pstr){
while(*pstr != 0) {
Transmitter1(*pstr++); 
}
}
unsigned char Receiver(void){
while((UART0->FR&0x10) != 0){};
return UART0->DR&0xFF;
}
void Transmitter(unsigned int data){
while((UART0->FR&0x20) != 0){};
UART0->DR = data;
}
void Transmitter1(unsigned char data){
while((UART0->FR&0x20) != 0){};
UART0->DR = data;
}
void PLL_Init(void)
{ 
SYSCTL->RCC2 |= 0x80000000; 
SYSCTL->RCC2 |= 0x00000800; 
SYSCTL->RCC = (SYSCTL->RCC &~0x000007C0) + 0x00000540; 
SYSCTL->RCC2 &= ~0x00000070; 
SYSCTL->RCC2 &= ~0x00002000; 
SYSCTL->RCC2 |= 0x40000000; 
SYSCTL->RCC2 = (SYSCTL->RCC2&~ 0x1FC00000) + (4<<22); 
while((SYSCTL->RIS&0x00000040)==0){}; 
SYSCTL->RCC2 &= ~0x00000800;
}

  • Hello Muhammed,

    Please use TivaWare for this application, not direct register programming.

    One of the primary purposes of TivaWare has been to remove the need for individual users to learn the ins and outs of Direct Register Access programming which can be complicated, confusing, and time consuming. TI has invested a lot of time and energy into making TivaWare into a robust software platform that can leveraged with all available peripherals.

    We cannot invest time in supporting re-making functionality that already exists within TivaWare, so if you need help from us then please use TivaWave.

    If you must eventually revert to direct register programming, you can always look at TivaWare source after your program is functional and learn from there how to make the calls you want on your own time.