I am doing a small embedded project, where I have 40 bits transferred via an interface like SPI. I pull these bits from the 32-bit bus and put the upper 32 bits into the variable uint32_tand the lower 8 bits into the variable uint8_t. I try to combine them into one uint64_t. However, when I shift to 8, it drops to the top 8 bits. Here is my code.
uint64_t getError()
{
uint32_t * disp_addr = (uint32_t*)(MYDISPLAY);
uint64_t error_upper;
uint8_t error_lower;
uint64_t error= 0;
error_lower = *(disp_addr+1);
error_upper = *(disp_addr+0);
error = ((uint64_t) error_upper) <<8 | error_lower;
return error;
}
This code works, except that it removes my 8 upper bits. Any thoughts or hints would be greatly appreciated. Thank.
change
uint64_t getError()
{
uint32_t * disp_addr = (uint32_t*)(MYDISPLAY);
uint64_t error_upper;
uint8_t error_lower;
uint64_t error= 0;
error_lower = 0x34;
error_upper = 0xABCDEF12;
error = ((uint64_t) error_upper) <<8 | error_lower;
printf("%010x", error);
}
Results: 00cdef1234
source
share