2024-07-19 06:49 AM
I am still new to STM and I am trying to perform a task on timer, I have written my code to configure the clock the my desired frequency and also I have written the code to set up my timer but when I downloaded the code to my board (stm32g070rb), my LED is supposed to blink for 3 seconds but it seems nothing is happening.
2024-07-19 10:34 AM - edited 2024-07-19 10:35 AM
> TIM3->ARR = 1 - 1; // Auto-reload value for 1 microsecond tick
This prevents timer from running.
JW
2024-07-19 12:57 PM
@waclawek.jan shows why the timer isn't running, but there are other issues.
You cannot interrupt the system at 1 MHz. There just isn't enough cpu resources to handle one interrupt before the next one happens, so your code will get stuck re-entering the interrupt and make no progress anywhere else.
Limit your interrupt frequency to 10 kHz or so. Less is better.
With a target 3 second toggle rate, set your timer update rate to 10 Hz or so to minimize overhead due to timer interrupts.
2024-07-22 04:24 PM
@TDK Can you kindly help me edit the code to meet this specification??? I've tried from my end the implement the change but then I still could not get it to work.
2024-07-22 06:52 PM - edited 2024-07-22 06:52 PM
The HAL_Delay function will give you a ms-precision delay. Given you are blinking LEDs, that should be more than sufficient.
If you need more precision, a free-running 32 bit counter (TIM2 or TIM5) is the best way to implement a delay. After setting up and starting the timer, the code to do the delay is very simple:
uint32_t start = TIM2->CNT;
while (TIM2->CNT - start < delta);
2024-07-23 02:40 AM
I am not using HAL library, is there any material you can recommend for programming STM32 from scratch using uVision. I use to have issues navigating the necessary materials online, all I have been seeing are either using cubeIDE or HAL library.
2024-07-23 05:55 AM
The reference manual has all the info you need if you want to do register-level programming.