cancel
Showing results for 
Search instead for 
Did you mean: 

Delay, multi milliseconds, on the STM32F0, again..

XooM
Senior

where I wrote it among the codes.. // Here I have to wait 500ms.
Can you help me to prevent the timers from being affected by this wait?
Can you give me the codes that I will add. Because I am very confused..

I tried many things but they all stopped the interrupts..

 

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{

	if(htim->Instance==TIM1)
	{
		
	if(input1==0) 
	{
		HAL_GPIO_WritePin(GPIOA, GPIO_Pin_1, GPIO_PIN_SET);
		// Here I have to wait 500ms.
		HAL_GPIO_WritePin(GPIOA, GPIO_Pin_1, GPIO_PIN_RESET);
	}

}

 

 

 

 

 

70 REPLIES 70
Karl Yamashita
Lead III

You must not have read the last sentence in the Wiki? It says you need to add a call to TimerCallbacktick. You should have a file stm32fxxx_it.c in the src folder that has the SysTick_Handler

void SysTick_Handler(void)
{
  /* USER CODE BEGIN SysTick_IRQn 0 */

  /* USER CODE END SysTick_IRQn 0 */
  HAL_IncTick();
  /* USER CODE BEGIN SysTick_IRQn 1 */
  TimerCallbackTick(&timerCallback);
  /* USER CODE END SysTick_IRQn 1 */
}

Yes, the Timercallback.c/h can be used for any microcontroller. You're not limited to the Systick at 1ms.

You could also create a Timer interrupt for 100us and use both Timercallback instances, one for 1ms, and the other 100us.  

 

 

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

I guess I'm really ***. No matter what I do, it doesn't work.

TimerCallbackTimerStart(&timerCallback, PA10_Off, 500, TIMER_NO_REPEAT);
doesn't work..
PA10_off function doesn't work.

Karl Yamashita
Lead III

Does PA10 turn on?

Attach your project

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

I couldn't do it with TimerCallback either
It didn't work like this either..
If PA2 is 0, PB14 should be 1 and PB14 should be 0 again for 500ms.

You uploaded the wrong project. It doesn't have the TimerCallback files.

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

Eklediğimde hata verdi. Dosyaları kaldırdım. Onları ekleyebilir misiniz? Onları ekleyip size tekrar haber vermeli miyim?
Bu projeye eklediğimde çok fazla hata alıyorum.

Ekledim ama sorunları çözemedim.

Karl Yamashita
Lead III

If you removed the files then how am i supposed to see what errors occurred? 

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

I added it in the message above and uploaded it again

Karl Yamashita
Lead III

Your project still looks the same. Your while loop is empty so not much is going to work.

 

KarlYamashita_0-1731887068373.png

Your project tree should look like this

KarlYamashita_2-1731888214248.png

 

You don't have GPIO set up correctly for the ones that use EXTI. Only the pins that you are polling use Input mode.

I highlighted from my IOC what it should be like.

KarlYamashita_1-1731887940217.png

 

The TimerCallback.c/h and PollingRoutine.c/h just drop in your project. The only thing you need to do is change the GPIO names i've used to the name you used.

 

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

I did everything you said, but the errors are not decreasing.
Can you look at my project file? Please, I'm stuck and can't continue.

note1: I recreated the project. I added the file, but I can't solve the errors.

note2: I enabled NVICs and added the project again.