Hello, I found a strange problem on S12G also on S12XE MCU. In our bootloader code, it will clear the RTIF bit (CPMUFLG_RTIF on S12G, CRGFLG_RTIF on S12XE), but I found other bits in the register also were cleared. PORF is used for power on reset judgement in my code, it can't be scratched.
My code is below:
CPMUFLG_RTIF = 1 // after this code, PORF is cleared.
CRGFLG_RTIF = 1 // after this code, PORF is cleared.
But if the code is as below, the PORF bit was not affected.
CPMUFLG = ~(U8)CPMUFLG_PORF_MASK; /* Clear CMPMU int flags - not needed but good practice */
It is normal behavior. It was explained N*N times on this forum. Pls search for clear flags, clearing flags etc. To clear just RTIF you need to either
CPMUFLG = CPMUFLG_RTIF_MASK;
CPMUFLG &= CPMUFLG_RTIF_MASK; // pls notice no ~ on the right, like one would use to zero memory bit (x &= ~1;)
Thank you, it works. But what's the difference? "CPMUFLG_RTIF = 1" or "CPMUFLG |= CPMUFLG_RTIF_MASK" is translated to "bset CPMUFLG, RTIF_MASK", why the bset instruction will aftect other bits?
Looks like you ignored my advice to search forums.
In short. Say you have flags registers, two flags are set, register reads as 3. You bset it with #1 mask. 3 | 1 = 3 and both flags are cleared. Simple. It doesn't matter all following variants are wrong
BSET reg, #1 ; clear all flags in reg
STAA reg ; clear all flags, which were read as set when LDAA instruction was executed
reg_BIT0 = 0; // clear all flags except BIT0
reg_BIT0 = 1; // clear all flags
Only these and equivalent are working with flags:
reg = 1;
reg &= 1;
BCLR reg, #~1 ; or BCLR reg, #0xFE