Hello, I am trying to use DHT11 to match your cool library to complete the temperature display. I found that the official DHT11 library cannot be used. I try to use the capture mode of the hardware timer to complete the driver. It works successfully, but it needs to pull it down for 18ms in the initial stage, I can't use vga.waitVSync(2) to complete the delay, I can only modify the source file to unlock the systick and use delay(18) to complete the pull down, But this seems to cause the screen to flicker. How should I solve this delay problem?
Below is my arduino code.
void Request() /* Microcontroller send request */
{
pinMode(DHT11, OUTPUT);
digitalWrite(DHT11,LOW); /* set to low pin */
delay(18); /* wait for 18ms */
//vga.waitVSync(2); /* it not work */
digitalWrite(DHT11,HIGH); /* set to high pin */
}
void Response()
{
pinMode(DHT11, INPUT_PULLUP);
Timer2.attachCompare1Interrupt(handler_channel_1);
TIMER2_BASE->CR1 = TIMER_CR1_CEN;
TIMER2_BASE->CR2 = 0;
TIMER2_BASE->SMCR = 0;
TIMER2_BASE->DIER = TIMER_DIER_CC1IE;
TIMER2_BASE->EGR = 0;
TIMER2_BASE->CCMR1 = TIMER_CCMR1_CC1S_INPUT_TI1;
TIMER2_BASE->CCMR2 = 0;
TIMER2_BASE->CCER = TIMER_CCER_CC1E;
TIMER2_BASE->PSC = 71;
TIMER2_BASE->ARR = 0xFFFF;
TIMER2_BASE->DCR = 0;
}
void handler_channel_1(void) { //This function is called when channel 1 is captured.
if (0b1 & GPIOA_BASE->IDR >> 0) { //If the receiver channel 1 input pulse on A0 is high.
channel_1_start = TIMER2_BASE->CCR1; //Record the start time of the pulse.
TIMER2_BASE->CCER |= TIMER_CCER_CC1P; //Change the input capture mode to the falling edge of the pulse.
}
else { //If the receiver channel 1 input pulse on A0 is low.
channel_1 = TIMER2_BASE->CCR1 - channel_1_start; //Calculate the total pulse time.
if (channel_1 < 0)channel_1 += 0xFFFF; //If the timer has rolled over a correction is needed.
TIMER2_BASE->CCER &= ~TIMER_CCER_CC1P; //Change the input capture mode to the rising edge of the pulse.
a[index1++]=channel_1;
}
}
Hello, I am trying to use DHT11 to match your cool library to complete the temperature display. I found that the official DHT11 library cannot be used. I try to use the capture mode of the hardware timer to complete the driver. It works successfully, but it needs to pull it down for 18ms in the initial stage, I can't use
vga.waitVSync(2)to complete the delay, I can only modify the source file to unlock the systick and usedelay(18)to complete the pull down, But this seems to cause the screen to flicker. How should I solve this delay problem?Below is my arduino code.