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

  1. #include "ble_uart.h"
  2. #define buffer_size 1024
  3. uint8_t data[128];
  4. int length = 0;
  5. void ble_uart_init(uart_port_t uart_num, int tx_io_num, int rx_io_num) {
  6. uart_config_t uart_config = {
  7. .baud_rate = 115200,
  8. .data_bits = UART_DATA_8_BITS,
  9. .parity = UART_PARITY_DISABLE,
  10. .stop_bits = UART_STOP_BITS_1,
  11. .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
  12. .source_clk = UART_SCLK_APB,
  13. };
  14. ESP_ERROR_CHECK(uart_driver_install(uart_num, buffer_size * 2, 0, 0, NULL, 0));
  15. ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));
  16. ESP_ERROR_CHECK(uart_set_pin(uart_num, tx_io_num, rx_io_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
  17. }
  18. void ble_receive(uart_port_t uart_num) {
  19. ESP_ERROR_CHECK(uart_get_buffered_data_len(uart_num, (size_t*)&length));
  20. if (length != 0) {
  21. length = uart_read_bytes(uart_num, data, length, 100);
  22. }
  23. }