modbus: update to support other targets

This commit is contained in:
Alex Lisitsyn
2021-11-08 16:28:55 +00:00
parent c49d9e152c
commit 0586be45d2
17 changed files with 125 additions and 92 deletions

View File

@@ -2,9 +2,9 @@ menu "Echo Example Configuration"
config EXAMPLE_UART_PORT_NUM
int "UART port number"
range 0 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3
range 0 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3
default 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3
range 0 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3
default 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3
default 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3
help
UART communication port number for the example.
@@ -22,6 +22,7 @@ menu "Echo Example Configuration"
range 0 34 if IDF_TARGET_ESP32
range 0 46 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
range 0 19 if IDF_TARGET_ESP32C3
range 0 47 if IDF_TARGET_ESP32S3
default 5
help
GPIO number for UART RX pin. See UART documentation for more information
@@ -32,6 +33,7 @@ menu "Echo Example Configuration"
range 0 34 if IDF_TARGET_ESP32
range 0 46 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
range 0 19 if IDF_TARGET_ESP32C3
range 0 47 if IDF_TARGET_ESP32S3
default 4
help
GPIO number for UART TX pin. See UART documentation for more information

View File

@@ -12,6 +12,7 @@
#include "driver/uart.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#include "esp_log.h"
/**
* This is an example which echos any data it receives on configured UART back to the sender,
@@ -34,6 +35,8 @@
#define ECHO_UART_BAUD_RATE (CONFIG_EXAMPLE_UART_BAUD_RATE)
#define ECHO_TASK_STACK_SIZE (CONFIG_EXAMPLE_TASK_STACK_SIZE)
static const char *TAG = "UART TEST";
#define BUF_SIZE (1024)
static void echo_task(void *arg)
@@ -63,9 +66,13 @@ static void echo_task(void *arg)
while (1) {
// Read data from the UART
int len = uart_read_bytes(ECHO_UART_PORT_NUM, data, BUF_SIZE, 20 / portTICK_RATE_MS);
int len = uart_read_bytes(ECHO_UART_PORT_NUM, data, (BUF_SIZE - 1), 20 / portTICK_RATE_MS);
// Write data back to the UART
uart_write_bytes(ECHO_UART_PORT_NUM, (const char *) data, len);
if (len) {
data[len] = '\0';
ESP_LOGI(TAG, "Recv str: %s", (char *) data);
}
}
}