How to use a Union to access and change the bits?
My header file:
typedef union {
struct {
uint8_t u_bit1:1;
uint8_t u_bit2:1;
uint8_t u_bit3:1;
uint8_t u_bit4:1;
uint8_t u_bit5:1;
uint8_t u_bit6:1;
uint8_t u_bit7:1;
uint8_t u_bit8:1;
} bits;
} u_serialSequenceBits;
My .c file:
u_serialSequenceBits myUnion;
myUnion.bits.u_bit2 = 1;
myUnion.bits.u_bit5 = 0;
The Errors:
Description Resource Path Location Type
expected '=', ',', ';', 'asm' or '__attribute__' before '.' token ihm.c /base_UPS_G070v2/Core/Src line 29 C/C++ Problem
Because this commands:
myUnion.bits.u_bit2 = 1;
and
myUnion.bits.u_bit5 = 0;
