Skip to main content
Aabc
Associate III
March 18, 2022
Solved

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

  • March 18, 2022
  • 4 replies
  • 2993 views

..

This topic has been closed for replies.
Best answer by Tesla DeLorean

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() ?

4 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
March 18, 2022

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Aabc
AabcAuthor
Associate III
March 19, 2022

Thanks for you

Piranha
Principal III
March 18, 2022

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

Aabc
AabcAuthor
Associate III
March 19, 2022

Thanks for you