2023-05-18 11:08 PM
Hi everyone, can anyone pls help me with the problem, i'm trying to read the unique ID of the stm32U585 controller, i'm able to read the ID with HAL functions, but im getting the same output for all the three different controller with different systems,
here is the code,
uid[0] = HAL_GetUIDw0();
uid[1] = HAL_GetUIDw1();
uid[2] = HAL_GetUIDw2();
// Convert unique ID to byte array
uid_buffer[0] = (uid[0] >> 24) & 0xFF;
uid_buffer[1] = (uid[0] >> 16) & 0xFF;
uid_buffer[2] = (uid[0] >> 8) & 0xFF;
uid_buffer[3] = uid[0] & 0xFF;
uid_buffer[4] = (uid[1] >> 24) & 0xFF;
uid_buffer[5] = (uid[1] >> 16) & 0xFF;
uid_buffer[6] = (uid[1] >> 8) & 0xFF;
uid_buffer[7] = uid[1] & 0xFF;
uid_buffer[8] = (uid[2] >> 24) & 0xFF;
uid_buffer[9] = (uid[2] >> 16) & 0xFF;
uid_buffer[10] = (uid[2] >> 8) & 0xFF;
uid_buffer[11] = uid[2] & 0xFF;
//snprintf((char*)uid_buffer, sizeof(uid_buffer), "\n\r %08X%08X%08X \n\r", uid[2], uid[1], uid[0]);
// Transmit the unique ID over UART
transmit_uart(uid_buffer, sizeof(uid_buffer));
output:
with extracting via three buffers 20353339575
extracting with individaul buffer from 0 to 11 $WRP 539
2023-05-19 07:40 AM
Set a debug breakpoint after you have filled the buffers and inspect the hex values. Your output doesn't make sense to me.
hth
KnarfB
2023-05-19 08:19 AM
Not exactly presenting as a compelling case. Try harder
Is your string buffer big enough?
2023-05-19 01:07 PM
> transmit_uart(uid_buffer, sizeof(uid_buffer));
Some bytes of the 'unique ID' look like ascii characters - but some are not. Print all bytes in hex.
2023-05-19 01:22 PM
char string[32]; // Transmit the unique ID over UART
transmit_uart((void *)string, snprintf(string, sizeof(string), "\n\r %08X%08X%08X \n\r", uid[2], uid[1], uid[0]));