Hi @ a2800276, apologies for the ambiguity. This is the board i am using
https://files.seeedstudio.com/wiki/XIAO ... C3-SCH.pdf
As you can see, it is a gpio 19 & 18 direct to the usb port.
This is a sample code of what i was doing in esp-idf, and it works when i was using GPIO 0 and 1
Code: Select all
#define BUF_SIZE (4096) // just a large buffer to ensure it can hold all data
#define ECHO_TEST_TXD 1
#define ECHO_TEST_RXD 0
#define ECHO_TEST_RTS (UART_PIN_NO_CHANGE)
#define ECHO_TEST_CTS (UART_PIN_NO_CHANGE)
#define UART_PORT_NUM 1
#define UART_BAUD_RATE 115200
void setup_UART_port(QueueHandle_t *queue_ptr)
{
/* Configure parameters of an UART driver,
* communication pins and install the driver */
uart_config_t uart_config = {
.baud_rate = UART_BAUD_RATE,
.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_DEFAULT,
};
/* intr struct for reference
uart_intr_config_t uart_interrupt = {
.intr_enable_mask = UART_RXFIFO_FULL_INT_RAW,
.rx_timeout_thresh = 1,
.txfifo_empty_intr_thresh = 10,
.rxfifo_full_thresh = 1,
};
*/
int intr_alloc_flags = 0;
ESP_ERROR_CHECK(uart_driver_install(UART_PORT_NUM, BUF_SIZE * 2, 0, 1, queue_ptr, intr_alloc_flags));
ESP_ERROR_CHECK(uart_param_config(UART_PORT_NUM, &uart_config));
ESP_ERROR_CHECK(uart_set_pin(UART_PORT_NUM, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS));
// ESP_ERROR_CHECK(uart_intr_config(UART_PORT_NUM, &uart_interrupt));
}
Wait_data_thread(void* param)
{
setup_UART_port(&handler);
while (1)
{
// blocking queue, if receive data, data will be queued and notify this thread
if (xQueueReceive(UART_queue, (void *)&event, (TickType_t)portMAX_DELAY))
{
switch (event.type)
{
case UART_DATA:
// Read data from the UART and wait 20ms(negligble), the checking is done by queue
int len = uart_read_bytes(UART_PORT_NUM, data, (BUF_SIZE - 1), 20 / portTICK_PERIOD_MS);
ESP_LOG_BUFFER_HEX("From uart", data, len);
if (len)
{
data[len] = '\0';
ESP_LOGI(TAG, "Recv str: %s", (char *)data);
unsigned char checksum_buff[len];
memcpy(checksum_buff, data, len);
/*
if (CRCCCITT(checksum_buff, len) != 0)
{
ESP_LOGE(TAG, "Data is corrupted from UART port!");
continue;
}
*/
}
else
{
ESP_LOGE(TAG, "NO DATA FROM UART PORT!");
continue;
}
opcode = extract_opcode(data);
unicast_addr = extract_addr(data);
esp_err_t err = Wait_backend_handler(opcode, unicast_addr, data, len);
if (err != ESP_OK)
{
ESP_LOGE(TAG, "Error in Wait_backend_handler");
}
break;
default:
ESP_LOGI(TAG, "UNHANDLED UART EVT");
break;
}
}
}
How i usually see if data can be received will be to open a serial port using PuTTY and set baud rate at 115200, before sending data via the terminal to see if the esp can receive. And it can receive.
Now i changed
Code: Select all
#define ECHO_TEST_TXD 19
#define ECHO_TEST_RXD 18
I also tried
Code: Select all
#define ECHO_TEST_TXD 18
#define ECHO_TEST_RXD 19
and enabled the CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG flag
When i tried writing using PuTTY, i am unable to get any data, in some instance the PuTTY terminal will just crash. i am still able to flash if i go into download mode by pressing the boot switch and reset switch (GPIO 9 LOW triggering thingy in the data sheet to go into download mode). But in default mode, i become unable to communicate through UART