Baudrate change done

This commit is contained in:
Duke NUCem 2021-10-11 19:01:47 +02:00
parent 33e70f5baf
commit d26079f722
3 changed files with 26 additions and 17 deletions

View File

@ -14,19 +14,17 @@
* - default value has index 0 */ * - default value has index 0 */
const uint32_t config_baudrates[] = { const uint32_t config_baudrates[] = {
19200, // 0 19200, // 0
1200, // 1 4800, // 1
2400, // 2 9600, // 2
4800, // 3 14400, // 3
9600, // 4 19200, // 4
14400, // 5 28800, // 5
19200, // 6 38400, // 6
28800, // 7 57600, // 7
38400, // 8 76800, // 8
57600, // 9 115200 // 9
76800, // 10
115200 // 11
}; };
const uint8_t config_baudrates_length = 12; const uint8_t config_baudrates_length = 10;
/* Function to lock the EEPROM */ /* Function to lock the EEPROM */
static int8_t eeprom_lock(void); static int8_t eeprom_lock(void);

View File

@ -228,6 +228,7 @@ int main(void)
/* SPS30 Init Time: max 30000 ms (datasheet pg. 2) */ /* SPS30 Init Time: max 30000 ms (datasheet pg. 2) */
LL_mDelay(1000); LL_mDelay(1000);
static uint32_t new_baud;
/* Enter the main loop */ /* Enter the main loop */
while (1) while (1)
@ -264,11 +265,21 @@ int main(void)
} }
if (baudrate_changed) if (baudrate_changed)
{ {
/* TODO: TEST */ while (!LL_LPUART_IsActiveFlag_TXE(LPUART1));
// LL_LPUART_Disable(LPUART1); LL_LPUART_Disable(LPUART1);
// MX_LPUART1_UART_Init(); LL_LPUART_DisableIT_IDLE(LPUART1);
// LL_LPUART_Enable(LPUART1); LL_LPUART_EnableIT_RXNE(LPUART1);
LL_LPUART_SetBaudRate(LPUART1, SYSTICK_FREQ_HZ, config_baudrates[sensor_config.baudrate_index]);
LL_LPUART_Enable(LPUART1);
LL_LPUART_EnableIT_IDLE(LPUART1);
LL_LPUART_EnableIT_RXNE(LPUART1);
LL_LPUART_EnableDirectionRx(LPUART1);
LL_LPUART_EnableDirectionTx(LPUART1);
baudrate_changed = 0; baudrate_changed = 0;
new_baud = LL_LPUART_GetBaudRate(LPUART1, SYSTICK_FREQ_HZ);
} }
/* It is time for measurement */ /* It is time for measurement */

View File

@ -32,7 +32,7 @@ CO2_alert_limit_1 = 1000
CO2_alert_limit_2 = 2000 CO2_alert_limit_2 = 2000
SCD4x_temperature_offset = 0 SCD4x_temperature_offset = 0
MODBUS_address = 254 MODBUS_address = 254
baudrate = 1 baudrate = 0
registers = [LED_on, LED_brightness, LED_smooth, CO2_alert_limit_1, CO2_alert_limit_2, SCD4x_temperature_offset, MODBUS_address, baudrate] registers = [LED_on, LED_brightness, LED_smooth, CO2_alert_limit_1, CO2_alert_limit_2, SCD4x_temperature_offset, MODBUS_address, baudrate]
# write to holding registers # write to holding registers
print('---- Writing to multiple holding registers ----') print('---- Writing to multiple holding registers ----')