SHOW:
|
|
- or go back to the newest paste.
| 1 | ||
| 2 | #include "stm32l4xx_hal.h" | |
| 3 | #include "delayus.h" | |
| 4 | ||
| 5 | static TIM_HandleTypeDef timer_handle; | |
| 6 | ||
| 7 | // incluye algo que falta y es indispensable | |
| 8 | ||
| 9 | ||
| 10 | void delayus (uint32_t microseconds) | |
| 11 | {
| |
| 12 | uint32_t overflows; | |
| 13 | - | while(comprobar flag) {};
|
| 13 | + | |
| 14 | - | borrar flag |
| 14 | + | uint32_t cnt_initial; |
| 15 | ||
| 16 | overflows = microseconds/65536 + 1; | |
| 17 | - | } |
| 17 | + | |
| 18 | partial = microseconds % 65536; | |
| 19 | cnt_initial = 65536 - partial; | |
| 20 | ||
| 21 | __HAL_TIM_CLEAR_FLAG(&timer_handle, TIM_FLAG_UPDATE); | |
| 22 | __HAL_TIM_SET_COUNTER(&timer_handle,??????); | |
| 23 | ||
| 24 | counter_flags = 0; | |
| 25 | while (counter_flags < overflows) | |
| 26 | {
| |
| 27 | while(comprobar flag == 0) {}; // __HAL_TIM_GET_FLAG(
| |
| 28 | // ????borrar flag | |
| 29 | counter_flags++; | |
| 30 | } | |
| 31 | ||
| 32 | HAL_TIM_Base_Stop( | |
| 33 | } | |
| 34 | ||
| 35 | void delay_init(void) | |
| 36 | {
| |
| 37 | // poner en macha el RCC del relpoj | |
| 38 | timer_handle.Instance = TIM6; | |
| 39 | timer_handle.Init.Prescaler = ... | |
| 40 | ||
| 41 | HAL_TIM_Base_Init( | |
| 42 | ||
| 43 | } | |
| 44 |