Обновление данных лидара поставлено на таймер 7

This commit is contained in:
2026-02-27 13:14:07 +03:00
parent 484dcf5843
commit 63df753fa8
3 changed files with 29 additions and 0 deletions

View File

@@ -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;