Browse Source

添加了串口透传

master
zwsd 3 years ago
parent
commit
7ac4dc63b5
  1. 5
      .vscode/settings.json
  2. 35
      main/main.c

5
.vscode/settings.json

@ -6,6 +6,9 @@
"stdio.h": "c",
"ble_spp_client_demo.h": "c",
"esp_gatt_common_api.h": "c",
"gpio.h": "c"
"gpio.h": "c",
"array": "c",
"string": "c",
"string_view": "c"
}
}

35
main/main.c

@ -14,9 +14,41 @@
#include "ble_spp_client_demo.h"
#include "key.h"
#include "driver/uart.h"
#define buffer_size 1024
static uint8_t rx_data_buffer[256];
int length = 0;
void motor_drive_hex_to_str(char *hex, int hex_len, char *str);
void ble_uart_init(uart_port_t uart_num, int tx_io_num, int rx_io_num)
{
uart_config_t uart_config = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.source_clk = UART_SCLK_APB,
};
ESP_ERROR_CHECK(uart_driver_install(uart_num, buffer_size * 2, 0, 0, NULL, 0));
ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));
ESP_ERROR_CHECK(uart_set_pin(uart_num, tx_io_num, rx_io_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
}
void ble_receive(uart_port_t uart_num)
{
ESP_ERROR_CHECK(uart_get_buffered_data_len(uart_num, (size_t *)&length));
if (length != 0)
{
length = uart_read_bytes(uart_num, rx_data_buffer, length, 100);
uart_write_bytes(UART_NUM_2, rx_data_buffer, length);
}
}
void app_main(void)
{
ble_init();
@ -24,9 +56,12 @@ void app_main(void)
key_init();
key_ble_send_cmd_reg(ble_key_cb);
ble_uart_init(UART_NUM_2, 18, 23);
while (true)
{
key_schedule();
ble_receive(UART_NUM_2);
}
}

Loading…
Cancel
Save