(Cubelde) I want to send uint8_t array and float variable with hal_uart_transmit. How can I do
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-04-14 09:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-04-14 09:30 AM
Use HAL_UART_Transmit() casting a pointer to the variable or array to (uint8_t *) and describing the size of it.
Basic C coding
float myarray[8];
HAL_UART_Transmit(&hUart2, (uint8_t *)myarray, sizeof(myarray), SOMETIMEOUT);
HAL_UART_Transmit(&hUart2, (uint8_t *)&myarray[0], sizeof(myarray), SOMETIMEOUT);
These things are just collections of bytes, review Data Representation if you are unfamiliar with how computers hold data in memory or files.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-04-14 12:17 PM
I have to learn how to send data in all data types. eg: float, string, byte, uint8_t array. Can you suggest a resource to me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-04-14 12:25 PM
K&R ?
char string[] = "Hello\r\n";
HAL_UART_Transmit(&hUart2, (uint8_t *)string, strlen(string), SOMETIMEOUT);
float flt = 123.45f;
HAL_UART_Transmit(&hUart2, (uint8_t *)&flt, sizeof(flt), SOMETIMEOUT);
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-04-14 02:07 PM
Float as a string
char string[16];
float flt = 123.45f;
HAL_UART_Transmit(&hUart2, (uint8_t *)string, sprintf(string,"%lf",flt), SOMETIMEOUT);
Up vote any posts that you find helpful, it shows what's working..
![](/skins/images/9117C6B72C9F598A212AA17633C1CC28/responsive_peak/images/icon_anonymous_message.png)