Реализован обработчик прерывания USART3
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
#include "lidar.h"
|
||||
|
||||
volatile uint8_t usart3_index = 0;
|
||||
volatile uint8_t usart3_checksum = 0;
|
||||
volatile uint8_t usart3_frame_ready = 0;
|
||||
static lidar_data_buf buffer;
|
||||
static uint8_t* buff_data = (uint8_t*)&buffer;
|
||||
|
||||
void lidar_init()
|
||||
{
|
||||
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOBEN;
|
||||
@@ -51,4 +57,35 @@ void lidar_init()
|
||||
|
||||
// Interrupt enable
|
||||
NVIC_EnableIRQ(USART3_IRQn);
|
||||
}
|
||||
|
||||
void USART3_IRQHandler()
|
||||
{
|
||||
if (USART3->ISR & USART_ISR_RXNE)
|
||||
{
|
||||
uint8_t b = USART3->RDR;
|
||||
|
||||
if (usart3_index < 2)
|
||||
{
|
||||
if (b == USART3_START_BYTE)
|
||||
buff_data[usart3_index++] = b;
|
||||
}
|
||||
else if (usart3_index < USART3_FRAME_SIZE)
|
||||
buff_data[usart3_index++] = b;
|
||||
|
||||
if (usart3_index == USART3_FRAME_SIZE)
|
||||
{
|
||||
for (uint8_t i = 0; i < USART3_FRAME_SIZE; ++i) usart3_checksum += buff_data[i];
|
||||
if (buffer.checksum == usart3_checksum)
|
||||
{
|
||||
usart3_index = 0;
|
||||
usart3_frame_ready = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
usart3_index = 0;
|
||||
usart3_frame_ready = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user