cancel
Showing results for 
Search instead for 
Did you mean: 

I would like send random number uint32_t via UART, but I cant see any number on serial console.

demir
Senior II

Hi,

I am using random number generator of STM32F407VGT-DISC1, which generates values between 0 to 4294967295. In order to make sure if I get random value for debug purposes, I want to write this value to serial console via UART. When I write my code as attached, I cant see the value at the serial console as expected. The code calls the hard fault handler. Nothing written on the console.

Could anyone please help me with this ?

 

demir_0-1707059111124.png

demir_1-1707059151005.png

 

 

2 REPLIES 2

It's binary data, think Data Representation 101, if you need it in human-readable ASCII form you'll need to use sprintf() or itoa()

Hard Faulting as you're casting the value, not a pointer to the value.

 

HAL_UART_Transmit(&huart2, (uint8_t*)&random32bit, sizeof(random32bit),HAL_MAX_DELAY);

 

char string[16];

HAL_UART_Transmit(&huart2, (uint8_t *)string, sprintf(string,"%u\n", random32bit), HAL_MAX_DELAY);

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

[deleted]