Why clearing RTIF bit will cause PORF, LVRF bit cleared also for S12 MCU?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Why clearing RTIF bit will cause PORF, LVRF bit cleared also for S12 MCU?

1,434 次查看
007
Contributor II

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:

S12G128 MCU:

CPMUFLG_RTIF = 1   // after this code, PORF is cleared.

 

S12XE256 MCU

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 */

标签 (1)
0 项奖励
回复
4 回复数

1,192 次查看
kef2
Senior Contributor V

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;

or

CPMUFLG &= CPMUFLG_RTIF_MASK;  // pls notice no ~ on the right, like one would use to zero memory bit  (x &= ~1;)

0 项奖励
回复

1,192 次查看
007
Contributor II

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?

0 项奖励
回复

1,192 次查看
kef2
Senior Contributor V

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

LDAA reg

ORAA #1

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

LDAA reg

ANDA  #1

STAA reg

LDAA #1

STAA  reg

0 项奖励
回复

1,192 次查看
007
Contributor II

Got it, thank you!

0 项奖励
回复