Page 1 of 1

trying to use uart_write_bytes() with integers

Posted: Thu Nov 04, 2021 6:01 pm
by noweare
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) ); 

Re: trying to use uart_write_bytes() with integers

Posted: Fri Nov 05, 2021 1:34 am
by ESP_Sprite
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.

Re: trying to use uart_write_bytes() with integers

Posted: Fri Nov 05, 2021 4:46 pm
by noweare
Ok, thank you.