Hi,
I have checked you issue and not able to reproduce the issue.
I have used following approach:
All used variables are global.
I am checking the value of the bitfield members in the “Variables” windov and there is no issue.
Are you able to do some simple test like presented to be sure there is nothing else in the SW which can influence the bitfield.
_c_test_buf test_ver_1;
static uint8_t a=0;
//----------------------------------------------------------------------------------
void CPMU_Init( void )
{
CPMUPROT = 0x26u; // Disable protection of clock configuration registers
// PLL setup 16 MHz BUSCLK from 4 MHz
CPMUSYNR = 0x03;
CPMUREFDIV = 0x40;
CPMUPOSTDIV = 0x00;
CPMUOSC_OSCE = 1;
while( CPMUIFLG_UPOSC == 0 ) {};
do
{
CPMUCLKS = 0B10000001; // COP clk is OSCCLK
}
while( CPMUCLKS != 0B10000001);
}
//----------------------------------------------------------------------------------
void bitfield_problem_solution_ctm_issue(void)
{
a++;
/* Note:- a can be 0 or 1 based on set or clear operation */
test_ver_1.test_var.test_bit_16 = ((uint8_t) (((uint8_t) (a)) & 0x01));
}
//----------------------------------------------------------------------------------
void main( void )
{
UWORD i,j;
//=== CLOCK and COP INIT =======
CPMU_Init(); //BUSCLK for 16MHz from OSCCLK 4MHz
for(;;)
{
bitfield_problem_solution_ctm_issue();
}
}
//----------------------------------------------------------------------------------
Best regards,
Ladislav