In access to a register with using bit field, the values read from the other bits are also written back along with the new value for the target member of the bit field.
Access to a special function register of the MCU with using bit field may, depending on the specification of the device you are using, lead to the setting of an unexpected value for bits other than those in the target member of the bit field.
In the following case, access by the register size and set a value for all bits.
- Value in the register changes between reading of the value and writing back the value.
- Writing back the value read from the member of bit field is not possible.
Refer to the examples in the following documents for further information.
- Related FAQ:
When the Data Frame Receive Pending Register (RXPR) is accessed with using bit field in order to clear the received Data Frames pending flag, other flags are also cleared at the same time. Why is this?
- Application Note:
Section 2.1.3, Notes on Bit-Field Access, in the SH7450 Group/SH7451 Group Register Definition Header File
Take care to check the hardware manual of the target product to make sure that your code is not attempting to violate restrictions the hardware imposes.
C/C++ Compiler Package for SuperH Family