From 63df753fa807a4de2bb234f5d073a5955fdf7c28 Mon Sep 17 00:00:00 2001 From: Radzhab Bisultanov Date: Fri, 27 Feb 2026 13:14:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D0=BB=D0=B8=D0=B4=D0=B0=D1=80=D0=B0=20=D0=BF=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BD=D0=B0=20=D1=82?= =?UTF-8?q?=D0=B0=D0=B9=D0=BC=D0=B5=D1=80=207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/BSP/Inc/lidar.h | 2 ++ Source/BSP/Src/lidar.c | 26 ++++++++++++++++++++++++++ Source/main.c | 1 + 3 files changed, 29 insertions(+) diff --git a/Source/BSP/Inc/lidar.h b/Source/BSP/Inc/lidar.h index 081d9d8..32d0848 100644 --- a/Source/BSP/Inc/lidar.h +++ b/Source/BSP/Inc/lidar.h @@ -32,6 +32,8 @@ typedef struct } lidar_data; void lidar_init(); +void lidar_tim7_init(); +void TIM7_DAC_IRQHandler(); void USART3_IRQHandler(); void lidar_update(lidar_data* lidar); diff --git a/Source/BSP/Src/lidar.c b/Source/BSP/Src/lidar.c index 6dd5023..9cdcb41 100644 --- a/Source/BSP/Src/lidar.c +++ b/Source/BSP/Src/lidar.c @@ -3,6 +3,7 @@ volatile uint8_t usart3_index = 0; volatile uint8_t usart3_checksum = 0; volatile uint8_t usart3_frame_ready = 0; +volatile uint8_t lidar_update_flag = 0; static lidar_data_buf buffer; static uint8_t* buff_data = (uint8_t*)&buffer; @@ -59,6 +60,28 @@ void lidar_init() NVIC_EnableIRQ(USART3_IRQn); } +void lidar_tim7_init() +{ + RCC->APB1ENR1 |= RCC_APB1ENR1_TIM7EN; + + TIM7->PSC = 16000 - 1; // 16 MHz / 16000 = 1000 Hz (1 ms) + TIM7->ARR = 10 - 1; // 10 ms + + TIM7->DIER |= TIM_DIER_UIE; // interrupt enable + TIM7->CR1 |= TIM_CR1_CEN; // counter enable + + NVIC_EnableIRQ(TIM7_DAC_IRQn); +} + +void TIM7_DAC_IRQHandler() +{ + if (TIM7->SR & TIM_SR_UIF) + { + TIM7->SR &= ~TIM_SR_UIF; + lidar_update_flag = 1; + } +} + void USART3_IRQHandler() { if (USART3->ISR & USART_ISR_RXNE) @@ -83,6 +106,9 @@ void USART3_IRQHandler() void lidar_update(lidar_data* lidar) { + if (!lidar_update_flag) + return; + if (!usart3_frame_ready) return; diff --git a/Source/main.c b/Source/main.c index 042bea3..edbf6be 100644 --- a/Source/main.c +++ b/Source/main.c @@ -39,6 +39,7 @@ int main(void) motors_init();*/ lidar_init(); + lidar_tim7_init(); while (1) {