Answer the question
In order to leave comments, you need to log in
How can uint32_t be interpreted into uint8_t registers?
Greetings!
Program for STM32.
There are uint32_t variables in memory, you need to send the variables via UART whose register is uint8_t.
There are a couple of options:
1) Through the union
uint8_t transmitBuffer[32];
union {
uint32_t var;
uint8_t a_var[4];
} interprVar;
uint32_t temp = 0xFFFF;
interpVar.var = temp;
for (unsigned char i = 0; i < 4; i++) {
transmitBuffer[i] = interprVar.a_var[i];
}
transmitBuffer[0] = 0x000000FF & (temp >> 24);
transmitBuffer[1] = 0x000000FF & (temp >> 16);
transmitBuffer[2] = 0x000000FF & (temp >> 8);
transmitBuffer[3] = 0x000000FF & (temp);
HAL_UART_Transmit_IT(&huart1, transmitBuffer, 4);
Answer the question
In order to leave comments, you need to log in
What jambs can await me?
void send_uint32(uint32_t v)
{
uint8_t transmitBuffer[4];
memcpy(transmitBuffer, &v, sizeof(v));
HAL_UART_Transmit_IT(&huart1, transmitBuffer, sizeof(v));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question