53 lines
1.6 KiB
C

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_ops.h"
#include "driver/i2c_master.h"
#include "esp_lcd_panel_vendor.h"
#include "esp_log.h"
#include <string.h>
#include "driver/uart.h"
static const char *TAG = "PMME-Device";
#define UART_NUM UART_NUM_2
#define BUF_SIZE 32
#define UART_BUF_SIZE 128
#define TXD_PIN 17
#define RXD_PIN 16
void app_main(void)
{
ESP_LOGI(TAG, "Initialize UART, Wait 1 second");
vTaskDelay(pdMS_TO_TICKS(1000));
ESP_LOGI(TAG, "Initialize UART, ok now go...");
uart_config_t uart_config = {
.baud_rate = 9600,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
// .rx_flow_ctrl_thresh = 122,
};
ESP_ERROR_CHECK(uart_param_config(UART_NUM, &uart_config));
ESP_ERROR_CHECK(uart_set_pin(UART_NUM, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
ESP_ERROR_CHECK(uart_driver_install(UART_NUM, UART_BUF_SIZE * 2, 0, 0, NULL, 0));
ESP_LOGI(TAG, "Create a simple pattern");
uint8_t uart_data[BUF_SIZE];
int frequency_check = 2000;
while (1) {
int len = uart_read_bytes(UART_NUM, uart_data, BUF_SIZE, frequency_check / portTICK_PERIOD_MS);
ESP_LOGI(TAG, "Received %d bytes from sensor", len);
if (len > 0) {
for(int i = 0; i < len && i < 16; i++) {
ESP_LOGI(TAG, "0x%02X", uart_data[i]);
}
}
vTaskDelay(pdMS_TO_TICKS(frequency_check));
}
}