UART Send Raw Bytes
UART Send Raw Bytes
The SDK UART API seems to send character only. How do I send a RAW byte? For example, I want to send data 0xAA.
Re: UART Send Raw Bytes
Might the uart_write_bytes API do the trick?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: UART Send Raw Bytes
Hi Kolban,
How do you send the raw bytes? Do you have example code?
How do you send the raw bytes? Do you have example code?
Re: UART Send Raw Bytes
I have the following code:
int sendData(const char* logName, const char* data)
{
const int len = strlen(data);
const int txBytes = uart_write_bytes(UART_NUM_2, data, len);
ESP_LOGI(logName, "Wrote %d bytes", txBytes);
return txBytes;
}
static void tx_task()
{
static const char *TX_TASK_TAG = "TX_TASK";
while (1) {
sendData(TX_TASK_TAG, 0xAA);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}
How do I declare the 0xAA as a byte? Currently the code expecting a string.
int sendData(const char* logName, const char* data)
{
const int len = strlen(data);
const int txBytes = uart_write_bytes(UART_NUM_2, data, len);
ESP_LOGI(logName, "Wrote %d bytes", txBytes);
return txBytes;
}
static void tx_task()
{
static const char *TX_TASK_TAG = "TX_TASK";
while (1) {
sendData(TX_TASK_TAG, 0xAA);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}
How do I declare the 0xAA as a byte? Currently the code expecting a string.
Re: UART Send Raw Bytes
Howdy my friend
how about
In this case, pass the size of your data buffer in as a parameter.
how about
Code: Select all
char data[] = { 0xAA };
sendData(data, sizeof(data));
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: UART Send Raw Bytes
Thank you very much. It works now!
Who is online
Users browsing this forum: Baidu [Spider], Bing [Bot], Google [Bot], Majestic-12 [Bot] and 184 guests