Code: Select all
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
};
uart_param_config(UART_NUM_2, &uart_config);
uart_set_pin(UART_NUM_2, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS);
uart_driver_install(UART_NUM_2, BUF_SIZE * 2, 0, 0, NULL, 0);
This is the portion that is writing and reading from UART_NUM2 (pins 18, 19)
// Configure a temporary buffer for the incoming data
uint8_t *data = (uint8_t *) malloc(BUF_SIZE);
char chex[8] = {0xfe, 0x01, 0x03, 0x05, 0x00, 0xff, 0xff, 0xff};
while (1) {
uint8_t buf[BUF_SIZE];
int testWrite = uart_write_bytes(UART_NUM_2, chex, sizeof(chex));
ESP_LOGI(LOG_TAG, "Size of sizeof(chex): %i", sizeof(chex));
int len = uart_read_bytes(UART_NUM_2, data, BUF_SIZE, 20 / portTICK_RATE_MS);
if (len > 0)
{
/* Log received data to the console. */
//data[len] = '\0';
ESP_LOGI(LOG_TAG, ">%s<", data);
uart_flush(UART_NUM_2);
}
Code: Select all
␛[0;32mI (192301) testUart: >�␁␃␅<␛[0m
␛[0;32mI (192301) testUart: Size of sizeof(chex): 8␛[0m
␛[0;32mI (192321) testUart: >�␁␃␅<␛[0m
␛[0;32mI (192321) testUart: Size of len: 8␛[0m
␛[0;32mI (192341) testUart: >�␁␃␅<␛[0m
␛[0;32mI (192341) testUart: Size of sizeof(chex): 8␛[0m
␛[0;32mI (192361) testUart: >�␁␃␅<␛[0m
␛[0;32mI (192361) testUart: Size of len: 8␛[0m