cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert array[3] to int and Transmit int via usatr (HAL_UART_Transmit). int y = atoi(str); converting char to int >> didn't work with me

Aabc
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions

Imagine you're not using an STM32, and just code it in C, perhaps trying building and understanding the equivalent code on a PC?

Do you understand how data is stored in memory?

Do you understand how to do decimal to/from binary, from first principles?

An array[3] of what?

int foo = 1234;

HAL_UART_Transmit(hUART, (uint8_t*)&foo, sizeof(foo), 100); // Send the bytes behind an int

int array[3] = { 1, 2, 3};

HAL_UART_Transmit(hUART, (uint8_t*)array, sizeof(array), 100); // Send the bytes behind an int array

You looking for itoa() ?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

4 REPLIES 4

Imagine you're not using an STM32, and just code it in C, perhaps trying building and understanding the equivalent code on a PC?

Do you understand how data is stored in memory?

Do you understand how to do decimal to/from binary, from first principles?

An array[3] of what?

int foo = 1234;

HAL_UART_Transmit(hUART, (uint8_t*)&foo, sizeof(foo), 100); // Send the bytes behind an int

int array[3] = { 1, 2, 3};

HAL_UART_Transmit(hUART, (uint8_t*)array, sizeof(array), 100); // Send the bytes behind an int array

You looking for itoa() ?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Piranha
Chief II

Before programming microcontrollers, one has to learn programming in general and the basics of the C language. Without that there is no chance of developing anything usable or even working at all. One can start here:

https://www.tutorialspoint.com/cprogramming/

https://www.cprogramming.com/tutorial/c-tutorial.html

And then continue here:

https://www.embeddedrelated.com/showarticle/453.php

Thanks for you

Thanks for you