trying to use uart_write_bytes() with integers

noweare
Posts: 74
Joined: Tue Jul 02, 2019 11:35 am

trying to use uart_write_bytes() with integers

Postby noweare » Thu Nov 04, 2021 6:01 pm

Can uart_write_bytes() be used to send integers out the serial port ?
I get an apostrophe " on the output so it looks like only ascii

Thank you

Code: Select all

int data_buf[10]={34,94,122,1223,4,5,6,7,8.9};
size_t bytes_wrote=uart_write_bytes(UART_NUM_0,(const int*)data_buf, sizeof(int) ); 

ESP_Sprite
Posts: 9749
Joined: Thu Nov 26, 2015 4:08 am

Re: trying to use uart_write_bytes() with integers

Postby ESP_Sprite » Fri Nov 05, 2021 1:34 am

Yes, you can, the code you put in there will write the first integer in data_buf to the serial port as four binary bytes, little-endian. You'd need to change the last parameter of uart_write_bytes to sizeof(int)*10 to output all of them.

Or did you want to output them as ASCII characters? In that case, you'd first need to convert them by e.g. doing a sprintf() into a 2nd buffer, then write that.

noweare
Posts: 74
Joined: Tue Jul 02, 2019 11:35 am

Re: trying to use uart_write_bytes() with integers

Postby noweare » Fri Nov 05, 2021 4:46 pm

Ok, thank you.

Who is online

Users browsing this forum: Dennie and 111 guests