This is an old revision of the document!


Timer Output




The code snippet bellow shows how to configure and use a GPIO pin as input.

#include "reg_stm32f4xx.h"
 
RCC->AHB1ENR |= (0x1 << 0u);          /* Enable GPIOA clock */
RCC->APB1ENR |= (0x1 << 0u);          /* Enable TIM2 clock */
 
/* configure output */
GPIOA->MODER |= (0x2 << 0u);          /* Set pin 0 to AF */
GPIOA->AFR[0] |= (0x1 << 0u);         /* Set pin 0 to AF1 (TIM2) */
 
/* configure basic timer */
TIM2->PSC = 84000u - 1u;              /* Counting with f = 84MHz / 84000 = 1MHz */
TIM2->ARR = 512u;                     /* Count to 512 */
 
/* configure timer output */
TIM2->CCMR1 |= (0x6 << 4u);           /* Enable PWM mode 1 on channel 1 */
TIM2->CCER |= (0x1 << 0u);            /* Enable output on channel 1 */
 
TIM2->CR1 |= (0x1 << 0u);             /* Start timer */


Hardware Abstraction Layer
Registry Types
InES Timer HAL Interface


Capture/compare mode register 1/2




DMA / Interrupt enable register




CCxDE0CCx DMA request disabled (reset state)
1CCx DMA request enabled
CCxIE0CCx interrupt disabled (reset state)
1CCx interrupt enabled

Capture/compare enable register




CCxE0Capture/compare output x disabled (reset state)
1Capture/compare output x enabled




  • stm32/peripherals/timer_output.1467114073.txt.gz
  • Last modified: 2016/06/28 11:41
  • by feur