Browse Source

添加了串口初始化

devtest
zwsd 3 years ago
parent
commit
bca497ffc7
  1. 8
      .vscode/settings.json
  2. 1
      main/CMakeLists.txt
  3. 27
      main/ble_uart.c
  4. 9
      main/ble_uart.h
  5. 9
      main/main.c

8
.vscode/settings.json

@ -25,6 +25,12 @@
"timer_u.h": "c",
"task.h": "c",
"string.h": "c",
"motor_drive.h": "c"
"motor_drive.h": "c",
"stdio.h": "c",
"stdlib.h": "c",
"esp_system.h": "c",
"esp_log.h": "c",
"ble_uart.h": "c",
"uart.h": "c"
},
}

1
main/CMakeLists.txt

@ -5,6 +5,7 @@ idf_component_register(SRCS #
"timer_u.c"
"ble_parse_data.c"
"motor_drive.c"
"ble_uart.c"
INCLUDE_DIRS #
"../dep/"
".")

27
main/ble_uart.c

@ -0,0 +1,27 @@
#include "ble_uart.h"
#define buffer_size 1024
uint8_t data[128];
int length = 0;
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, data, length, 100);
}
}

9
main/ble_uart.h

@ -0,0 +1,9 @@
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "driver/uart.h"
void ble_uart_init(uart_port_t uart_num, int tx_io_num, int rx_io_num);
void ble_receive(uart_port_t uart_num);

9
main/main.c

@ -8,6 +8,7 @@
#include "string.h"
//
#include "ble_spp_server_demo.h"
#include "ble_uart.h"
#include "motor_drive.h"
#include "timer_u.h"
@ -51,7 +52,9 @@ void app_main(void) {
constructor_bluetooth_processer(&s_bluetooth_processer);
ble_spp_server_demo_app_main(&s_bluetooth_processer);
timer_group_init(TIMER_GROUP_0, TIMER_0, false, timer_group0_interval_num, timer_interval_ms);
motor_drive_uart_init();
// motor_drive_uart_init();
// ble_uart_init(UART_NUM_2, 4, 5);
// char* test_str = "This is a test string.\n";
while (true) {
bluetooth_gatts_try_process_data();
@ -64,6 +67,10 @@ void app_main(void) {
ESP_LOGI("test", "info log ok\n");
s_bluetooth_processer.motor_drive_turn_flag = false;
}
// uart_write_bytes(UART_NUM_2, (const char*)test_str, strlen(test_str));
// ets_delay_us(1000000);
// ble_receive(UART_NUM_2);
}
return;

Loading…
Cancel
Save