exploring-the-different-modes-of-timer-operation-in-stm32

by Marwen Maghrebi
#include "main.h"
#include"stdio.h"

int main(void)
{
uint8_t MSG[10] = {'\0'};
uint8_t CounterTicks;

  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_USART1_UART_Init();

  while (1)
  { 
//Timer Periodic Interrupt Mode
 if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0)== GPIO_PIN_SET)
    {
      HAL_TIM_Base_Start_IT(&htim3);
    }
    //Timer Counter Mode
    else if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_1)==GPIO_PIN_SET)
    {
      HAL_TIM_Base_Start_IT(&htim1);
      CounterTicks = TIM1->CNT;
      sprintf(&MSG,"Ticks = %d  ",CounterTicks);
      HAL_UART_Transmit(&huart1, MSG, sizeof(MSG), 100);
      HAL_UART_Transmit(&huart1, (uint8_t*)&"\n\r", 2, 2);
      HAL_Delay(200);
    }
    else if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_2)==GPIO_PIN_SET)
    {
      HAL_TIM_OC_Start(&htim2, TIM_CHANNEL_2);
      HAL_TIM_OC_Start(&htim2, TIM_CHANNEL_4);
    }
    else
    {
      HAL_TIM_Base_Stop(&htim3);
      HAL_TIM_Base_Stop(&htim1);
      HAL_TIM_OC_Stop(&htim2, TIM_CHANNEL_2);
      HAL_TIM_OC_Stop(&htim2, TIM_CHANNEL_4);
    }
  }
}
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00