2025-04-29 2:53 AM - last edited on 2025-04-29 3:07 AM by Andrew Neil
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.
2025-04-29 2:57 AM
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?
2025-04-29 3:00 AM
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.
2025-04-29 3:05 AM - edited 2025-04-29 3:10 AM
@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?
2025-04-29 3:11 AM
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)
2025-04-29 3:21 AM
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();
}
}
2025-04-29 3:29 AM
@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 ...
2025-04-29 3:32 AM - edited 2025-04-29 3:33 AM
@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?
2025-04-29 3:44 AM - edited 2025-04-29 3:51 AM
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
2025-04-29 3:58 AM - edited 2025-04-29 4:00 AM
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?