diff --git a/examples/knx-demo-esp-idf/main/main.cpp b/examples/knx-demo-esp-idf/main/main.cpp index e0e167f..5a491fe 100644 --- a/examples/knx-demo-esp-idf/main/main.cpp +++ b/examples/knx-demo-esp-idf/main/main.cpp @@ -123,8 +123,9 @@ extern "C" void app_main(void) { ESP_LOGI(TAG, "WiFi initialization finished."); - // Set UART pins (example: RX=16, TX=17) - knxPlatform.knxUartPins(16, 17); + // Configure UART settings + knxPlatform.knxUartPins(16, 17); // Set RX=16, TX=17 + knxPlatform.knxUartBaudRate(19200); // Set baud rate (can be changed to other values like 9600, 38400, etc.) knxPlatform.setupUart(); // Set button ISR diff --git a/src/esp32_idf_platform.cpp b/src/esp32_idf_platform.cpp index 08a6ee3..0e0b3be 100644 --- a/src/esp32_idf_platform.cpp +++ b/src/esp32_idf_platform.cpp @@ -44,6 +44,12 @@ void Esp32IdfPlatform::knxUartPins(int8_t rxPin, int8_t txPin) _txPin = txPin; } +void Esp32IdfPlatform::knxUartBaudRate(uint32_t baudRate) +{ + _baudRate = baudRate; + ESP_LOGI(KTAG, "UART baud rate set to %d", _baudRate); +} + void Esp32IdfPlatform::setNetif(esp_netif_t* netif) { _netif = netif; @@ -66,7 +72,7 @@ void Esp32IdfPlatform::setupUart() return; uart_config_t uart_config; memset(&uart_config, 0, sizeof(uart_config)); - uart_config.baud_rate = 19200; + uart_config.baud_rate = _baudRate; // Use configurable baud rate uart_config.data_bits = UART_DATA_8_BITS; uart_config.parity = UART_PARITY_EVEN; uart_config.stop_bits = UART_STOP_BITS_1; @@ -77,6 +83,7 @@ void Esp32IdfPlatform::setupUart() ESP_ERROR_CHECK(uart_param_config(_uart_num, &uart_config)); ESP_ERROR_CHECK(uart_set_pin(_uart_num, _txPin, _rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); _uart_installed = true; + ESP_LOGI(KTAG, "UART initialized with baud rate %d", _baudRate); } void Esp32IdfPlatform::closeUart() diff --git a/src/esp32_idf_platform.h b/src/esp32_idf_platform.h index 43e61ef..58f83cf 100644 --- a/src/esp32_idf_platform.h +++ b/src/esp32_idf_platform.h @@ -18,6 +18,7 @@ class Esp32IdfPlatform : public Platform // uart void knxUartPins(int8_t rxPin, int8_t txPin); + void knxUartBaudRate(uint32_t baudRate); // Add baud rate configuration // Call this after WiFi/Ethernet has started and received an IP. void setNetif(esp_netif_t* netif); @@ -74,6 +75,7 @@ class Esp32IdfPlatform : public Platform uart_port_t _uart_num; int8_t _rxPin = -1; int8_t _txPin = -1; + uint32_t _baudRate = 19200; // Default baud rate, can be changed bool _uart_installed = false; // NVS (for EEPROM emulation)