Could be something to do with the alignment of data in your struct. Maybe it is aligned on 32 bit boundaries. Perhaps you will need to specify that it be packed to 8 bit boundaries?
Try loading test data eg a,b,c,d,e,f,g into your 23 byte array then access the struct members to see how they line up with test data. Also look at the memory view in the simulator to see where things go when you write to the struct compared to where you think they should go.
Nothing is actually ''wrong'' - this kind of behaviour is entirely to be expected! The fundamental issue with this technique is that it is
not
portable - is it completely and entirely reliant upon the specific implementation details of the particular compiler used! As already noted, the specific implementation details most likely to be involved are data alignment, padding, data sizes, and byte ordering. You might be able to get this to work by re-defining the union - or it might be better to just start from scratch...
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Yes, that should address the specific issue of alignment/packing - but it still leaves the other issues of data sizes, byte ordering, etc unaddressed.
Again, the basic problem is that this approach is fundamentally non-portable - so there should be no expectation that it will ''just work'' when moved to a different target and/or a different compiler! There isn't even a guarantee that it will continue to work between different versions of the same compiler!
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.