Added Uart
This commit is contained in:
parent
9cbfb58656
commit
479162e47b
@ -1,2 +1,2 @@
|
|||||||
idf_component_register(SRCS "hw_test.c" "bosch456.c"
|
idf_component_register(SRCS "hw_test.c" "bosch456.c" "uart.c"
|
||||||
INCLUDE_DIRS ".")
|
INCLUDE_DIRS ".")
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "led_strip.h"
|
#include "led_strip.h"
|
||||||
|
#include "uart.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "bosch456.h"
|
#include "bosch456.h"
|
||||||
|
|
||||||
@ -13,8 +14,6 @@
|
|||||||
#define TASTER_GPIO 12
|
#define TASTER_GPIO 12
|
||||||
#define V_LIPO_1 1
|
#define V_LIPO_1 1
|
||||||
#define V_LIPO_2 12
|
#define V_LIPO_2 12
|
||||||
#define TERMAINL_RX 2
|
|
||||||
#define TERMINAL_TX 3
|
|
||||||
#define DIP_MASTER 4
|
#define DIP_MASTER 4
|
||||||
#define I2C_SCL 5
|
#define I2C_SCL 5
|
||||||
#define I2C_SDA 6
|
#define I2C_SDA 6
|
||||||
@ -180,4 +179,5 @@ void app_main(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init_bma456(bus_handle);
|
init_bma456(bus_handle);
|
||||||
|
init_uart();
|
||||||
}
|
}
|
||||||
|
|||||||
39
main/uart.c
Normal file
39
main/uart.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include "driver/uart.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "hal/uart_types.h"
|
||||||
|
#include "uart.h"
|
||||||
|
|
||||||
|
#define MASTER_UART UART_NUM_1
|
||||||
|
#define BUF_SIZE (256)
|
||||||
|
#define TERMAINL_RX 2
|
||||||
|
#define TERMINAL_TX 3
|
||||||
|
|
||||||
|
void uart_read_task(void *param) {
|
||||||
|
uint8_t *data = (uint8_t *)malloc(BUF_SIZE);
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
len = uart_read_bytes(MASTER_UART, data, BUF_SIZE, pdMS_TO_TICKS(20));
|
||||||
|
if (len > 0) {
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
ESP_LOGI("UART", "UART: %c", data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_uart() {
|
||||||
|
uart_config_t uart_config = {// .baud_rate = 115200, // 921600, 115200
|
||||||
|
.baud_rate = 921600,
|
||||||
|
.data_bits = UART_DATA_8_BITS,
|
||||||
|
.parity = UART_PARITY_DISABLE,
|
||||||
|
.stop_bits = UART_STOP_BITS_1,
|
||||||
|
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE};
|
||||||
|
|
||||||
|
uart_driver_install(MASTER_UART, BUF_SIZE * 2, 0, 0, NULL, 0);
|
||||||
|
uart_param_config(MASTER_UART, &uart_config);
|
||||||
|
uart_set_pin(MASTER_UART, TERMINAL_TX, TERMAINL_RX, UART_PIN_NO_CHANGE,
|
||||||
|
UART_PIN_NO_CHANGE);
|
||||||
|
|
||||||
|
xTaskCreate(uart_read_task, "Read Uart", 4096, NULL, 1, NULL);
|
||||||
|
}
|
||||||
2
main/uart.h
Normal file
2
main/uart.h
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
void init_uart();
|
||||||
Loading…
x
Reference in New Issue
Block a user