2026-05-08 7:04 PM
Greetings, I'm trying to set up TIM4 per the reference manual (RM0016).
With the clock set to LSI at 128kHz, the following code causes the PD2 output pin to appear constantly high visually via a wired LED. I would expect it would be blinking once per second. I don't have access to a scope so I can't see what is actually happening. Anyone spot anything I'm doing incorrectly?
sim
; F_Master Prescalar tim clk
; 128_000 Hz / 1024 = 125
mov TIM4_PSCR, #0b1010 ; 2 ** 0b1010 = 1024 prescaler
; ARR at 0x7d = 125
mov TIM4_ARR, #0x7d
bset TIM4_IER, #0 ; UIE: Update interrupt enable
bset TIM4_CR1, #0 ; CEN: Counter enable...and the interrupt code:
tim4_up_isr:
; PD2 blinks once per second
; from TIM4
bres TIM4_SR, #0 ; UIF: Update interrupt flag
bcpl PD_ODR, #2
iret...fwiw when I set line 5 of the interrupt code to use bres PD_ODR, #2, the output appears low visually.