Compare commits
2 Commits
2b3e4129e8
...
385aa66ffc
| Author | SHA1 | Date | |
|---|---|---|---|
| 385aa66ffc | |||
| 8a3336c994 |
@@ -31,6 +31,10 @@ typedef struct
|
|||||||
} lidar_data;
|
} lidar_data;
|
||||||
|
|
||||||
void lidar_init();
|
void lidar_init();
|
||||||
|
void USART3_IRQHandler();
|
||||||
void lidar_update(lidar_data* lidar);
|
void lidar_update(lidar_data* lidar);
|
||||||
|
|
||||||
|
void lidar_i2c2_init();
|
||||||
|
void lidar_i2c2_update();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -37,7 +37,7 @@ void lidar_init()
|
|||||||
USART3->BRR = 16000000UL / 115200UL;
|
USART3->BRR = 16000000UL / 115200UL;
|
||||||
|
|
||||||
// parity control disable
|
// parity control disable
|
||||||
USART3->CR1 &= ~(USART_CR1_PCE);
|
USART3->CR1 &= ~USART_CR1_PCE;
|
||||||
|
|
||||||
// word length 8 bit
|
// word length 8 bit
|
||||||
USART3->CR1 &= ~USART_CR1_M1 & ~USART_CR1_M0;
|
USART3->CR1 &= ~USART_CR1_M1 & ~USART_CR1_M0;
|
||||||
@@ -50,7 +50,7 @@ void lidar_init()
|
|||||||
USART3->CR1 |= USART_CR1_RE | USART_CR1_RXNEIE;
|
USART3->CR1 |= USART_CR1_RE | USART_CR1_RXNEIE;
|
||||||
|
|
||||||
// overrun disable
|
// overrun disable
|
||||||
USART3->CR3 |= USART_CR3_OVRDIS;
|
// USART3->CR3 |= USART_CR3_OVRDIS;
|
||||||
|
|
||||||
// USART3 enable
|
// USART3 enable
|
||||||
USART3->CR1 |= USART_CR1_UE;
|
USART3->CR1 |= USART_CR1_UE;
|
||||||
@@ -59,8 +59,10 @@ void lidar_init()
|
|||||||
NVIC_EnableIRQ(USART3_IRQn);
|
NVIC_EnableIRQ(USART3_IRQn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t test;
|
||||||
void USART3_IRQHandler()
|
void USART3_IRQHandler()
|
||||||
{
|
{
|
||||||
|
++test;
|
||||||
if (USART3->ISR & USART_ISR_RXNE)
|
if (USART3->ISR & USART_ISR_RXNE)
|
||||||
{
|
{
|
||||||
uint8_t b = USART3->RDR;
|
uint8_t b = USART3->RDR;
|
||||||
@@ -97,3 +99,29 @@ void lidar_update(lidar_data* lidar)
|
|||||||
lidar->strength = buffer.strength_l | (buffer.strength_h << 8);
|
lidar->strength = buffer.strength_l | (buffer.strength_h << 8);
|
||||||
lidar->temperature = buffer.temp_l | (buffer.temp_h << 8);
|
lidar->temperature = buffer.temp_l | (buffer.temp_h << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lidar_i2c2_init()
|
||||||
|
{
|
||||||
|
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN;
|
||||||
|
|
||||||
|
GPIOA->MODER &= ~(3 << (8 * 2)) & ~(3 << (9 * 2));
|
||||||
|
GPIOA->MODER |= 2 << (8 * 2) | 2 << (9 * 2); // alt func mode
|
||||||
|
|
||||||
|
GPIOA->AFR[1] &= ~(0xF << 0) & ~(0xF << 4);
|
||||||
|
GPIOA->AFR[1] |= 4 << 0 | 4 << 4; // AF4
|
||||||
|
|
||||||
|
GPIOA->OTYPER |= 1 << 8 | 1 << 9; // open-drain
|
||||||
|
|
||||||
|
GPIOA->PUPDR &= ~(3 << (8 * 2)) & ~(3 << (9 * 2));
|
||||||
|
GPIOA->PUPDR |= 1 << (8 * 2) | 1 << (9 * 2); // pull-up
|
||||||
|
|
||||||
|
RCC->APB1ENR1 |= RCC_APB1ENR1_I2C2EN; // enable I2C2
|
||||||
|
I2C2->TIMINGR = 0x00303D5B; // 400 kHz @ 16 MHz
|
||||||
|
I2C2->CR1 |= I2C_CR1_PE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "radio_receiver.h"
|
#include "radio_receiver.h"
|
||||||
#include "motors.h"
|
#include "motors.h"
|
||||||
#include "pid.h"
|
#include "pid.h"
|
||||||
|
#include "lidar.h"
|
||||||
|
|
||||||
|
|
||||||
imu_scaled_t imu;
|
imu_scaled_t imu;
|
||||||
@@ -12,6 +13,7 @@ attitude_t attitude;
|
|||||||
rc_channels rx_chs_raw;
|
rc_channels rx_chs_raw;
|
||||||
rc_channels rx_chs_normalized;
|
rc_channels rx_chs_normalized;
|
||||||
control_channels_t ctrl_chs;
|
control_channels_t ctrl_chs;
|
||||||
|
lidar_data lidar;
|
||||||
|
|
||||||
void delay_ms(uint32_t ms);
|
void delay_ms(uint32_t ms);
|
||||||
|
|
||||||
@@ -19,7 +21,8 @@ int main(void)
|
|||||||
{
|
{
|
||||||
__enable_irq();
|
__enable_irq();
|
||||||
|
|
||||||
NVIC_SetPriority(TIM6_DAC_IRQn, 1);
|
NVIC_SetPriority(TIM6_DAC_IRQn, 2);
|
||||||
|
NVIC_SetPriority(USART3_IRQn, 1);
|
||||||
NVIC_SetPriority(LPUART1_IRQn, 0);
|
NVIC_SetPriority(LPUART1_IRQn, 0);
|
||||||
|
|
||||||
imu_pow_init();
|
imu_pow_init();
|
||||||
@@ -35,6 +38,8 @@ int main(void)
|
|||||||
|
|
||||||
motors_init();
|
motors_init();
|
||||||
|
|
||||||
|
lidar_init();
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
attitude_update(&attitude, &imu);
|
attitude_update(&attitude, &imu);
|
||||||
@@ -44,6 +49,8 @@ int main(void)
|
|||||||
|
|
||||||
attitude_pid_update(&ctrl_chs, &rx_chs_normalized, &attitude, &imu);
|
attitude_pid_update(&ctrl_chs, &rx_chs_normalized, &attitude, &imu);
|
||||||
|
|
||||||
|
lidar_update(&lidar);
|
||||||
|
|
||||||
if (rx_chs_normalized.rc_armed)
|
if (rx_chs_normalized.rc_armed)
|
||||||
{
|
{
|
||||||
motors_set_throttle_mix(rx_chs_normalized.rc_throttle, &ctrl_chs, rx_chs_normalized.rc_armed);
|
motors_set_throttle_mix(rx_chs_normalized.rc_throttle, &ctrl_chs, rx_chs_normalized.rc_armed);
|
||||||
|
|||||||
Reference in New Issue
Block a user