First commit
This commit is contained in:
parent
38b53a45a0
commit
02ad9b7596
9
.clang-format
Normal file
9
.clang-format
Normal file
@ -0,0 +1,9 @@
|
||||
# We'll use defaults from the LLVM style, but with some modifications so that it's close to the CDT K&R style.
|
||||
BasedOnStyle: LLVM
|
||||
UseTab: Always
|
||||
IndentWidth: 4
|
||||
TabWidth: 4
|
||||
PackConstructorInitializers: NextLineOnly
|
||||
BreakConstructorInitializers: AfterColon
|
||||
IndentAccessModifiers: false
|
||||
AccessModifierOffset: -4
|
3
.clangd
Normal file
3
.clangd
Normal file
@ -0,0 +1,3 @@
|
||||
CompileFlags:
|
||||
CompilationDatabase: build
|
||||
Remove: [-m*, -f*]
|
16
.cproject
Normal file
16
.cproject
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
<cconfiguration id="org.eclipse.cdt.core.default.config.1477596397">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.core.defaultConfigDataProvider" id="org.eclipse.cdt.core.default.config.1477596397" moduleId="org.eclipse.cdt.core.settings" name="Configuration">
|
||||
<externalSettings/>
|
||||
<extensions/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
</cconfiguration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.pathentry">
|
||||
<pathentry excluding="**/CMakeFiles/**" kind="out" path="build"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
</cproject>
|
20
.project
Normal file
20
.project
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>uart_async_rxtxtasks</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.core.cBuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.core.ccnature</nature>
|
||||
<nature>com.espressif.idf.core.idfNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
2
.settings/org.eclipse.core.resources.prefs
Normal file
2
.settings/org.eclipse.core.resources.prefs
Normal file
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
6
CMakeLists.txt
Normal file
6
CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
# The following lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(uart_async_rxtxtasks)
|
2
main/CMakeLists.txt
Normal file
2
main/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "uart_async_rxtxtasks_main.c"
|
||||
INCLUDE_DIRS ".")
|
56
main/uart_async_rxtxtasks_main.c
Normal file
56
main/uart_async_rxtxtasks_main.c
Normal file
@ -0,0 +1,56 @@
|
||||
#include <stdio.h>
|
||||
#include "driver/uart.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_log.h"
|
||||
#include "string.h"
|
||||
|
||||
#define UART_NUM UART_NUM_1
|
||||
#define TXD_PIN GPIO_NUM_17
|
||||
#define RXD_PIN GPIO_NUM_16
|
||||
#define BUF_SIZE 1024
|
||||
|
||||
static const char *TAG = "UART";
|
||||
|
||||
void uart_init(void) {
|
||||
uart_config_t uart_config = {
|
||||
.baud_rate = 4800,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||
};
|
||||
uart_param_config(UART_NUM, &uart_config);
|
||||
uart_set_pin(UART_NUM, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
uart_driver_install(UART_NUM, BUF_SIZE * 2, 0, 0, NULL, 0);
|
||||
}
|
||||
|
||||
void uart_send_command(const uint8_t *command, size_t length) {
|
||||
uart_write_bytes(UART_NUM, (const char *)command, length);
|
||||
}
|
||||
|
||||
int uart_receive_response(uint8_t *data, size_t length) {
|
||||
return uart_read_bytes(UART_NUM, data, length, pdMS_TO_TICKS(1000));
|
||||
}
|
||||
|
||||
void request_current_value(void) {
|
||||
uint8_t command[] = {0xA5, 0x05,0x4C, 0x4C, 0x42}; // Example command to request current value
|
||||
uart_send_command(command, sizeof(command));
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
|
||||
uint8_t response[31];
|
||||
int len = uart_receive_response(response, sizeof(response));
|
||||
if (len > 0) {
|
||||
ESP_LOGI(TAG, "Received %d bytes", len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
ESP_LOGI(TAG, "0x%02X", response[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void) {
|
||||
uart_init();
|
||||
while (1) {
|
||||
request_current_value();
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user