2021-03-22 10:55 PM
There is a array:
uint8_t dat[8] = {0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xdc, 0x5e, 0x40};
It means a double variable data in memery. The value is 123.45.
This code can be run in my computer:
int main(int argc, char *argv[])
{
uint8_t dat[] = {0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xdc, 0x5e, 0x40};
double test = *((double*)dat);
printf("%.3f\r\n", test);
return 0;
}
It will put: 123.450
But on stm32f103rct6. It will stuck when I run this:
double test = *((double*)dat);
But use float will not stuck:
float test = *((float*)dat);
So, how can I convert memery to double rightly on stm32f103? (I use stm32cubeide)
Thanks!
Solved! Go to Solution.
2021-03-24 05:17 AM
Thank you! I have solved this problem by making a buffer.
But I still don't understand why.
'dat' is given by other progress. I'v printed and checked the content is right. But I'll get hardfault.
'buf' is copied from 'dat'. And it works fine.
2021-03-24 06:52 AM
Copying one uint8_t array to another array of the same type will not solve anything. You will have to learn about alignment and unions. :) But you can start with an example from there: