# STM32F401RE Nucleo failing to read DHT22 sensor

This is my first project and I am trying to read the temperature readings from a DHT22 sensor using a STM32F401RE-NUCLEO board.

My code is failing at reading the input from the DHT22 sensor when I use the CCR1 command. I have verified my circuit is working as I previously tested it using the MBED compiler.

I set up the timer to use TIM_CHANNEL_1 and TIM3 instance, which according to the STM32CubeMX GUI corresponds to STM32 pin PA6.

My DHT22 structure looks like the following:

typedef struct{
uint8_t             bitsRX[5];
float               temp;
float               hum;
uint8_t             crcErrorFlag;
DHT22_STATE         state;
TIM_HandleTypeDef   timHandle;
TIM_IC_InitTypeDef  timICHandle;
uint32_t            timChannel;
uint16_t            gpioPin;
GPIO_TypeDef*       gpioPort;
int                 bitPos;
IRQn_Type           timerIRQn;
uint32_t            gpioAlternateFunction;
uint16_t            lastVal;
void                (*errorCallback)(DHT22_RESULT);
}


I set up my DHT object as the following:

dht.gpioPin = GPIO_PIN_6;
dht.gpioPort = GPIOA;
dht.timChannel = TIM_CHANNEL_1;
dht.gpioAlternateFunction = GPIO_AF2_TIM3;
dht.timHandle.Instance = TIM3;


I am running the following command to try and capture the value:

uint16_t val = HAL_TIM_ReadCapturedValue(&dht->timHandle, dht->timChannel);


Where the function is defined as the following (snipped off the later parts since I only care about channel 1):

uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel)
{
uint32_t tmpreg = 0U;

__HAL_LOCK(htim);
switch (Channel)
{
case TIM_CHANNEL_1:
{
/* Check the parameters */
assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
/* Return the capture 1 value */

tmpreg = htim->Instance->CCR1; // This line is giving me the problem

break;
}


The tmpreg = htim->Instance->CCR1 is always returning 0.

Any solutions or pointers that may help me?