I believe your issue is that the structure size is still a byte. I'm not sure if there is a better way but you might want to look into doing something like this (Instead of a union):
Yes, I'm aware of the problem (see my first message). I would like to avoid using functions here, hence I was asking if there is any way to overcome this byte alignment.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi!
We need to use custom structures of BITS (not BOOLs) in our projects. For example:
...and ST_7bit in the same way. This is mandatory due to requirements of certain devices.
I combine 3bit and 7bit with a further structure:
Then, I do a union of the combined structure with WORD.
This doesn't work as I would expect. st3bit is copied to WORD correctly but st7bit is byte-aligned to the higher byte of the WORD.
Example: uUnionTest.st3_7.st3bit.x1 TRUE --> wTest is 256.
Is there any way I could pack the bits and omit the byte-alignment?
Please provide ST_3bit_7bit code (copy/paste issue). Providing the expected bit partern over a word would also help.
Last edit: dFx 2020-03-23
Hi,
here's ST_3bit_7bit:
In pic1 the result is as expected.
In pic2 I would expect value 15.
Last edit: pekkallio 2020-03-23
I believe your issue is that the structure size is still a byte. I'm not sure if there is a better way but you might want to look into doing something like this (Instead of a union):
Last edit: Lo5tNet 2020-03-24
Yes, I'm aware of the problem (see my first message). I would like to avoid using functions here, hence I was asking if there is any way to overcome this byte alignment.