Hi, everyone,
Now I use S32K146, I define a union type variable as follow:
typedef union unCanFrameData
{
UINT8 u8Data[CAN_FRAME_DATA_LEN]; ///< 8 uint8 data
UINT16 u16Data[4]; ///< 4 uint16 data
UINT32 u32Data[2]; ///< 2 uint32 data
}UN_CAN_FRAME_DATA;
But when I set the u16Data[2]:
unData.u16Data[2] = 2000
I get the follow result:
The problem is that the u16Data[2] is 2000, but the u8Data[4] and u8Data[5] is 0, the data is not Coincident.
Can anyone help me? Thanks.
Solved! Go to Solution.
Hi Erich.
I have solved this issue.
The root is that I define UINT16 as unsigned int.
In S32K CPU, unsigned int is 4 bytes long. Not 2 bytes.
This make the union alain failure.
Thanks.
hello,I'm Chinese people,if you too,can you tell me your qq number,I'd like to ask you some questions。thank you so mach.
Hi, I am sorry. I didn't use QQ.
I you would, you can ask me via this platform.
I quickly tried that, but I get a reasonable result:
with
typedef uint8_t UINT8;
typedef uint16_t UINT16;
typedef uint32_t UINT32;
#define CAN_FRAME_DATA_LEN 8
typedef union unCanFrameData
{
UINT8 u8Data[CAN_FRAME_DATA_LEN]; ///< 8 uint8 data
UINT16 u16Data[4]; ///< 4 uint16 data
UINT32 u32Data[2]; ///< 2 uint32 data
}UN_CAN_FRAME_DATA;
and
unData.u16Data[2] = 2000;
I believe it could be some compiler settings you are using (can you share a small example project)?
I used the S32K144 (don't think it matters), but can you check that 0x2000'ef58 you indeed have RAM?
I hope this helps,
Erich
Hi Erich.
I have solved this issue.
The root is that I define UINT16 as unsigned int.
In S32K CPU, unsigned int is 4 bytes long. Not 2 bytes.
This make the union alain failure.
Thanks.
Hi Erich,
I think it could be something about union settings. Even I set the union variable to be global, it happen this error again:
Could you tell me where to set the union or the data type setting?
Thanks.