Skip to main content
Graduate II
February 4, 2024
Question

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

  • February 4, 2024
  • 2 replies
  • 1516 views

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

 

 

    This topic has been closed for replies.

    2 replies

    Graduate II
    February 4, 2024

    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);

    Super User
    February 4, 2024

    [deleted]