Починен приём данных с пульта
This commit is contained in:
@@ -17,6 +17,9 @@ void receiver_gpio_init()
|
|||||||
GPIOA->AFR[0] &= ~(0xF << (3 * 4));
|
GPIOA->AFR[0] &= ~(0xF << (3 * 4));
|
||||||
GPIOA->AFR[0] |= 12 << (3 * 4);
|
GPIOA->AFR[0] |= 12 << (3 * 4);
|
||||||
|
|
||||||
|
GPIOA->OSPEEDR &= ~(3 << (3 * 2));
|
||||||
|
GPIOA->OSPEEDR |= 2 << (3 * 2);
|
||||||
|
|
||||||
// pull-up
|
// pull-up
|
||||||
GPIOA->PUPDR &= ~(3 << (3 * 2));
|
GPIOA->PUPDR &= ~(3 << (3 * 2));
|
||||||
GPIOA->PUPDR |= 1 << (3 * 2);
|
GPIOA->PUPDR |= 1 << (3 * 2);
|
||||||
@@ -37,7 +40,7 @@ void receiver_uart_init()
|
|||||||
LPUART1->CR2 = 0;
|
LPUART1->CR2 = 0;
|
||||||
LPUART1->CR3 = 0;
|
LPUART1->CR3 = 0;
|
||||||
|
|
||||||
LPUART1->BRR = (256 * 16000000UL) / 100000UL;
|
LPUART1->BRR = SystemCoreClock / (100000UL / 256);
|
||||||
|
|
||||||
// parity control enable
|
// parity control enable
|
||||||
LPUART1->CR1 |= USART_CR1_PCE | USART_CR1_M0;
|
LPUART1->CR1 |= USART_CR1_PCE | USART_CR1_M0;
|
||||||
@@ -59,10 +62,13 @@ void receiver_uart_init()
|
|||||||
// receiver enable
|
// receiver enable
|
||||||
// interrupt generated whenever ORE = 1 or RXNE = 1
|
// interrupt generated whenever ORE = 1 or RXNE = 1
|
||||||
LPUART1->CR1 |= USART_CR1_RE | USART_CR1_RXNEIE;
|
LPUART1->CR1 |= USART_CR1_RE | USART_CR1_RXNEIE;
|
||||||
|
|
||||||
|
LPUART1->CR3 |= USART_CR3_OVRDIS;
|
||||||
|
|
||||||
// uart enable
|
// uart enable
|
||||||
LPUART1->CR1 |= USART_CR1_UE;
|
LPUART1->CR1 |= USART_CR1_UE;
|
||||||
|
|
||||||
|
NVIC_SetPriority(LPUART1_IRQn, 0);
|
||||||
NVIC_EnableIRQ(LPUART1_IRQn);
|
NVIC_EnableIRQ(LPUART1_IRQn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,11 +78,11 @@ void receiver_init()
|
|||||||
receiver_uart_init();
|
receiver_uart_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LPUART1_IRQHandler()
|
extern "C" void LPUART1_IRQHandler()
|
||||||
{
|
{
|
||||||
if (LPUART1->ISR & USART_ISR_RXNE)
|
if (LPUART1->ISR & USART_ISR_RXNE)
|
||||||
{
|
{
|
||||||
uint8_t b = LPUART1->RDR;
|
char b = LPUART1->RDR;
|
||||||
|
|
||||||
if (b == SBUS_START_BYTE)
|
if (b == SBUS_START_BYTE)
|
||||||
sbus_index = 0;
|
sbus_index = 0;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#define RADIO_RECEIVER_H
|
#define RADIO_RECEIVER_H
|
||||||
|
|
||||||
#include "stm32g431xx.h"
|
#include "stm32g431xx.h"
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#define SBUS_FRAME_SIZE 25
|
#define SBUS_FRAME_SIZE 25
|
||||||
#define SBUS_START_BYTE 0X0F
|
#define SBUS_START_BYTE 0X0F
|
||||||
@@ -22,7 +21,6 @@ void receiver_gpio_init();
|
|||||||
void receiver_lpuart_clock_init();
|
void receiver_lpuart_clock_init();
|
||||||
void receiver_uart_init();
|
void receiver_uart_init();
|
||||||
void receiver_init();
|
void receiver_init();
|
||||||
void LPUART1_IRQHandler();
|
|
||||||
void receiver_update(rc_channels* chs);
|
void receiver_update(rc_channels* chs);
|
||||||
void receiver_parse_frame();
|
void receiver_parse_frame();
|
||||||
rc_channels normalize_channels(rc_channels chs);
|
rc_channels normalize_channels(rc_channels chs);
|
||||||
|
|||||||
@@ -130,6 +130,8 @@ int main()
|
|||||||
SystemClock_Config(); // 170MHz
|
SystemClock_Config(); // 170MHz
|
||||||
IMU_InitPower();
|
IMU_InitPower();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TICK_Init();
|
TICK_Init();
|
||||||
|
|
||||||
TIM6_Init(TIM_PRIORITY, 500, TimerUpdateSensor, TimerUpdateMain);
|
TIM6_Init(TIM_PRIORITY, 500, TimerUpdateSensor, TimerUpdateMain);
|
||||||
@@ -140,9 +142,9 @@ int main()
|
|||||||
TIM6_Enable();
|
TIM6_Enable();
|
||||||
TIM7_Enable();
|
TIM7_Enable();
|
||||||
|
|
||||||
attitude_t attitude;
|
static attitude_t attitude;
|
||||||
rc_channels rx_chs_raw;
|
static rc_channels rx_chs_raw;
|
||||||
rc_channels rx_chs_normalized;
|
static rc_channels rx_chs_normalized;
|
||||||
static control_channels_t ctrl_chs;
|
static control_channels_t ctrl_chs;
|
||||||
|
|
||||||
attitude_init(&attitude);
|
attitude_init(&attitude);
|
||||||
|
|||||||
Reference in New Issue
Block a user