Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/knx-demo-esp-idf/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/esp32_idf_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 %lu", _baudRate);
}

void Esp32IdfPlatform::setNetif(esp_netif_t* netif)
{
_netif = netif;
Expand All @@ -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;
Expand All @@ -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 %lu", _baudRate);
}

void Esp32IdfPlatform::closeUart()
Expand Down
2 changes: 2 additions & 0 deletions src/esp32_idf_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
Loading