One of following two accesses is definitely not going to be aligned to short boundary, and ARM doesn't handle this. (Also, they look wrong even if it'd worked?)
The following methods should be safe, they operate one byte at a time.
unsigned short a; unsigned char b[100]; memcpy(&a,&b[x+ 0],sizeof(unsigned short)); -OR- a = ((unsigned short)b[x + 0] << 0) + ((unsigned short)b[x + 1] << 8); You just can't use casts to arbitrarily change a pointer type and load it. -Clive
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
There seems to be a misunderstanding of how to use pointers, you don't need the '&' when you access the content of str[], only when you want the address (ie &str[])
color = ((unsigned short)(str[ 2 * temp]) << 0) + ((unsigned short)(str[ (2 * temp)+1]) << 8); How are you calling the routine? void foo(const unsigned char *str); const unsigned char data[] = { 0x01, 0x02, 0x03, 0x04 }; foo(data); // Or foo(&data[0]);
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
The Hard Fault indicates you are reading/writing to an illegal location.
You'll have to debug it. Suggest removing the LCD_xxx calls and see if it still traps. Try outputting some instrumentation to the serial debug port, etc.
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..