cancel
Showing results for 
Search instead for 
Did you mean: 

Using TIM6 and TIM2 in STM32f407 Discovery board: DHT11 sensor and CAN frames

Azizz
Associate III

Hello everyone,

I'm using the STM32f407 Discovery board.
I'm trying to use TIM2 to send a frame in a cyclic way and also i'm using TIM6 to send the data of a DHT11 sensor. The problem is that when i added the TIM6 i no longer receiver the frames.
Who should i adjust my code in order to work with the DHT11 sensor data and still send my frames.
I tried to use the DHT11 sensor separately to make sure that the code works and it works perfectly.

14 REPLIES 14
mƎALLEm
ST Employee

Hello,

First, could you please state on this thread? if the provided answer solved your issue please accept it as solution.

Second, 


@Azizz wrote:

The problem is that when i added the TIM6 i no longer receiver the frames.


Which frame? CAN frames? if yes from which node?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Azizz
Associate III

The problem occurs in these lines 

  if (HAL_TIM_Base_Start_IT(&htim2) != HAL_OK)
   {
     Error_Handler();
  }

  HAL_TIM_OC_Start_IT(&htim2, TIM_CHANNEL_1);

I cannot send any frame neither the cyclic one or the frame sent by request.


@Azizz wrote:

The problem occurs in these lines 


What problem occurs, exactly?

Does it hit the Error-Handler ?

If so, look at what value HAL_TIM_Base_Start_IT returned; step into it to find why ...

 


@Azizz wrote:

when i added the TIM6 i no longer receiver the frames.


Is that because nothing is transmitted at all, or the transmission becomes "bad"?

If "bad", in what way(s) is it bad?

 

PS:

 


@Azizz wrote:

I'm trying to use TIM2 to send a frame in a cyclic way and also i'm using TIM6 to send the data of a DHT11 sensor. The problem is that when i added the TIM6 i no longer receiver the frames.


If you just start TIM6 without doing any DHT11 stuff, are the [CAN?] frames still OK

ie, is it the timer itself, or something else in your DHT11 code that's causing the problem?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
Azizz
Associate III

It is not transmitted at all and when i remove these lines the program works but the frame is no longer send cyclically.
It doesn't hit he error handler when i try to use the step over button in the line showed below, it blocks the program.

  if (HAL_TIM_Base_Start_IT(&htim2) != HAL_OK)



Yess when i remove the line commented i receive the frames

void Send_Cyclic_Frame_A (void) {
	uint8_t temp = 0, humi = 0;

    //DHT11_GetData(&temp, &humi);

	TxHeader.StdId = 0x103;
	TxHeader.RTR = CAN_RTR_DATA;
	TxHeader.IDE = CAN_ID_STD;
	TxHeader.DLC = 2;
	TxHeader.TransmitGlobalTime = DISABLE;

	TxData[0] = temp;
	TxData[1] = humi;

	if (HAL_CAN_AddTxMessage(&hcan1, &TxHeader, TxData, &TxMailbox)!= HAL_OK )
	{
		   Error_Handler();
	}
}

@Azizz wrote:

 when i try to use the step over button in the line showed below, it blocks the program.


So step into that function to see where & why it blocks ...

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

@Azizz wrote:

Yes when i remove the line commented i receive the frames

void Send_Cyclic_Frame_A (void) {
   uint8_t temp = 0, humi = 0;

   //DHT11_GetData(&temp, &humi);

So look into what's happening within that DHT11_GetData() function...

Is it blocking?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Inside the DHT11_GetData() i call the function 

uint8_t DHT11_Check_Response(void) {
    delay_us(40);
    if (!(HAL_GPIO_ReadPin(DHT11_PORT, DHT11_PIN))) {
        delay_us(80);
        if ((HAL_GPIO_ReadPin(DHT11_PORT, DHT11_PIN))) {
            delay_us(50);
            return 1;
        }
    }
    return 0;
}

I think the problem comes from the use of delay_us() or HAL_delay but i don't know how to replace them with an alternative

So that function will block for at least 40us, up to  a maximum of 170us.

If you just put such a delay into your  Send_Cyclic_Frame_A  function, does that show the same symptoms?

 

PS:

How is your delay_us implemented?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.