Реализована инциализация GPIOB11 и USART3
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#include "lidar.h"
|
||||
|
||||
void lidar_init()
|
||||
{
|
||||
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOBEN;
|
||||
|
||||
// port 11 alt func mode
|
||||
GPIOB->MODER &= ~(3 << (11 * 2));
|
||||
GPIOB->MODER |= 2 << (11 * 2);
|
||||
|
||||
// set AF7 on AFRegister for GPIOB11
|
||||
GPIOB->AFR[1] &= ~(0xF << 12);
|
||||
GPIOB->AFR[1] |= 7 << 12;
|
||||
|
||||
// very high speed
|
||||
GPIOB->OSPEEDR |= 3 << (11 * 2);
|
||||
|
||||
// pull-up
|
||||
GPIOB->PUPDR &= ~(3 << (11 * 2));
|
||||
GPIOB->PUPDR |= 1 << (11 * 2);
|
||||
|
||||
// SYSCLK selected as USART3 clock
|
||||
RCC->CCIPR &= ~(RCC_CCIPR_USART3SEL);
|
||||
RCC->CCIPR |= 1 << RCC_CCIPR_USART3SEL_Pos;
|
||||
RCC->APB1ENR1 |= RCC_APB1ENR1_USART3EN;
|
||||
|
||||
USART3->CR1 = 0;
|
||||
USART3->CR2 = 0;
|
||||
USART3->CR3 = 0;
|
||||
|
||||
USART3->BRR = 16000000UL / 115200UL;
|
||||
|
||||
// parity control disable
|
||||
USART3->CR1 &= ~(USART_CR1_PCE);
|
||||
|
||||
// word length 8 bit
|
||||
USART3->CR1 &= ~USART_CR1_M1 & ~USART_CR1_M0;
|
||||
|
||||
// 1 stop bit
|
||||
USART3->CR2 &= ~USART_CR2_STOP;
|
||||
|
||||
// receiver enable
|
||||
// interrupt generated whenever ORE = 1 or RXNE = 1
|
||||
USART3->CR1 |= USART_CR1_RE | USART_CR1_RXNEIE;
|
||||
|
||||
// overrun disable
|
||||
USART3->CR3 |= USART_CR3_OVRDIS;
|
||||
|
||||
// USART3 enable
|
||||
USART3->CR1 |= USART_CR1_UE;
|
||||
|
||||
// Interrupt enable
|
||||
NVIC_EnableIRQ(USART3_IRQn);
|
||||
}
|
||||
Reference in New Issue
Block a user