Send bytes over UART

NIghthunter101
Posts: 9
Joined: Thu Feb 06, 2020 3:49 am

Send bytes over UART

Postby NIghthunter101 » Thu Feb 06, 2020 3:59 am

I'm trying to control a TMC2009 driver over UART and I need to send the commands as bytes but I only seem to be able to send characters. What do I need to change to get it sending bytes not characters?
I've got the following code for the UART,

Code: Select all

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, "0xA000004F");
		vTaskDelay(2000 / portTICK_PERIOD_MS);
	}
}

somesh
Posts: 36
Joined: Tue Jun 25, 2019 6:44 am
Location: Pune
Contact:

Re: Send bytes over UART

Postby somesh » Thu Feb 06, 2020 5:06 am

NIghthunter101 wrote:
Thu Feb 06, 2020 3:59 am
I'm trying to control a TMC2009 driver over UART and I need to send the commands as bytes but I only seem to be able to send characters. What do I need to change to get it sending bytes not characters?
I've got the following code for the UART,

Code: Select all

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, "0xA000004F");
		vTaskDelay(2000 / portTICK_PERIOD_MS);
	}
}
you need to convert string into hex bytes or directly send bytes by allocating in an array.
for example, uint8_t a[]={0xA0,0x00,0x00,0x4F};
Thanks,
Somesh Burkule

NIghthunter101
Posts: 9
Joined: Thu Feb 06, 2020 3:49 am

Re: Send bytes over UART

Postby NIghthunter101 » Thu Feb 06, 2020 5:22 am

uart_write_bytes needs a char not uint8_t. Is there a different function I should be using or do I have to make something new?

somesh
Posts: 36
Joined: Tue Jun 25, 2019 6:44 am
Location: Pune
Contact:

Re: Send bytes over UART

Postby somesh » Thu Feb 06, 2020 7:37 am

NIghthunter101 wrote:
Thu Feb 06, 2020 5:22 am
uart_write_bytes needs a char not uint8_t. Is there a different function I should be using or do I have to make something new?
you can use char also.
Thanks,
Somesh Burkule

Who is online

Users browsing this forum: No registered users and 388 guests