diff --git a/Core/Inc/pressure_wrapper.h b/Core/Inc/pressure_wrapper.h index ca1de62..05a5c9a 100644 --- a/Core/Inc/pressure_wrapper.h +++ b/Core/Inc/pressure_wrapper.h @@ -20,7 +20,7 @@ namespace PressureConversions { } constexpr uint32_t voltageToPascals(uint32_t voltage_mv) noexcept { - return voltage_mv * 6895u / 4u * 37u / 9u; + return voltage_mv * 68950u / 4u * 37u / 9u; } constexpr uint32_t pascalsToDepthMm(uint32_t pascals) noexcept { diff --git a/Core/Src/main.cpp b/Core/Src/main.cpp index 4347ead..e1824a9 100644 --- a/Core/Src/main.cpp +++ b/Core/Src/main.cpp @@ -15,7 +15,7 @@ extern "C" { #include "hydrolib_bus_application_master.hpp" -#define BUFFER_LENGTH 5 // TODO:make variable +constexpr uint32_t kTransmitPeriodMs = 5; // 200 Hz constinit hydrv::GPIO::GPIOLow rx_pin(hydrv::GPIO::GPIOLow::GPIOA_port, 10, hydrv::GPIO::GPIOLow::GPIO_UART_RX); @@ -105,12 +105,19 @@ int main(void) { /* USER CODE BEGIN 2 */ sensor.init(); RS.Init(); - + + uint32_t lastTransmitTick = HAL_GetTick(); + while (1) { manager.Process(); sensor.poll(); depth = sensor.getDepthMm(); - master.Write(static_cast(&depth), 0, sizeof(depth)); + + const uint32_t now = HAL_GetTick(); + if (now - lastTransmitTick >= kTransmitPeriodMs) { + lastTransmitTick = now; + master.Write(static_cast(&depth), 0, sizeof(depth)); + } } /* USER CODE END 3 */ } @@ -129,7 +136,7 @@ void SystemClock_Config(void) { */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV2; + RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;