You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
867 B
27 lines
867 B
#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);
|
|
}
|
|
}
|