This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Struct 8 and 16 bits size

How do I load and access elements with different sizes in a structure?
I'm trying to adapt a code for STM32F103.
The original structure is defined like this:

typedef struct// FFB: PID Pool Feature Report
{
   uint8_t   reportId;   // =7
   uint16_t   ramPoolSize;   // ?
   uint8_t      maxSimultaneousEffects;   // ?? 40?
   uint8_t      memoryManagement;   // Bits: 0=DeviceManagedPool, 1=SharedParameterBlocks
} USB_FFBReport_PIDPool_Feature_Data_t;

My code starts and accesses like this:

struct USB_FFBReport_PIDPool_Feature_Data_t ;   
...
USB_FFBReport_PIDPool_Feature_Data_t ans;
uint8_t *Feature(uint16_t Length)
{
...
 ans.reportId = 7;
 ans.ramPoolSize = 0xffff;
 ans.maxSimultaneousEffects = 14;
 ans.memoryManagement = 3;   
   
 return (uint8_t *) &ans;   
}

The above routine returns me:
07
00
FF
FF
0E


The correct is:
07
FF
FF
0E
03

To have the correct values ​​I have to leave the fields of the structure all with a byte (uint8_t).

typedef struct// FFB: PID Pool Feature Report
{
   uint8_t   reportId;   
   uint8_t   ramPoolSizeH; 
   uint8_t   ramPoolSizeL;   
   uint8_t      maxSimultaneousEffects;   
   uint8_t      memoryManagement;   
} USB_FFBReport_PIDPool_Feature_Data_t;

How should I proceed to access or load the structure correctly?