Read a register map: bit fields, offsets and reserved bits
Atlasbot · 23/8/2026 · 11 min read
The article Timeing diagram discussed signal relations over time. The last Datasheet Read column goes to the register map — table listing the control/status registers of an IC, and the correct read to configure it with code.
Key concepts
Register map is a table listing every register that an IC exposes to software read/write, each row typically consisting of: offset (relative address from the device's original address), register name, access (R = read only, W = write only, R/W = read and write), and functional description. Each register is typically 8/16/32-bit wide, and is internally split into bit fields — contiguous bit groups that carry a specific meaning (e.g., 2 mode-selective bits, 1 on/off bit).
How it works
Real-world address to read/write a register from the base address (usually the device's I2C/SPI address) plus the offset written in the register map. Within each register, a number of bits are marked Reserved — these are bits reserved for future or manufacturer internal purposes, with no published significance. Most datasets require that when writing a register containing a reserved bit, read the current value first, only change the correct bit field to be changed, keep the reserved bit unchanged, and then write the entire register — this technique is called read-modify-write.
Summarized: Register map is the lingua franca between the datasheet and the code — each bit of which has definite (or purposely undefined, with reserved bit) meaning. Directly writing a fixed value to the register irrespective of what the reserved bit contains is a dangerous habit, although often "runs" in the initial fast test.
Technical details
Formulas
Compute the absolute address of a register, and extract the value of a particular bit field by bit + mask translation:
Register_address = Base_Address + Offset
Example: I2C sensor with Base_Address = 0x68, CTRL register at Offset 0x00
CTRL_address = 0x68 + 0x00 = 0x68 (first byte sent after the device address)
Extract bit field M1:M0 (bits 3:2) from the CTRL register value:
mode = (gia_tri_thanh_ghi >> 2) & 0b11
(shift right by 2 bits to move M1:M0 to the lowest position, then AND with a 2-bit mask)
Set EN (bit 4) to 1 WITHOUT changing the other bits (read-modify-write):
gia_tri_moi = (gia_tri_hien_tai | (1 << 4))
Parameters
| Engineering | Used when |
|---|---|
(value >> n) & mask | Read (export) a specific field bit |
value | (1 << n) | Set a particular bit to 1, keep other bits the same |
value & ~(1 << n) | Clear a specific bit to 0, keep other bits unchanged |
value ^ (1 << n) | Toggle a specific bit |
Practical applications
When configuring an IMU such as MPU6050 (learned in MPU6050, the Sensor & Perception section) over I2C, selecting the full scale range of the accelerometer/gyroscope is essentially writing the correct bit field in the corresponding configuration register — if the register map is not carefully read and inadvertently overrides the register with a fixed value, which can inadvertently turn off other features that are enabled by other bits in the same register without any knowledge.
Practical example
def doc_gia_tri_thanh_ghi(i2c, dia_chi_thiet_bi, offset):
return i2c.read_byte(dia_chi_thiet_bi, offset) # simulated
def ghi_bit_field(gia_tri_hien_tai, vi_tri_bit, so_bit, gia_tri_moi):
mask = ((1 << so_bit) - 1) << vi_tri_bit
return (gia_tri_hien_tai & ~mask) | ((gia_tri_moi << vi_tri_bit) & mask)
# Scenario: read current CTRL register and change only field M1:M0 (position 2, width 2 bits)
gia_tri_hien_tai = 0b00110101 # assume these values are read from the actual device
gia_tri_moi = ghi_bit_field(gia_tri_hien_tai, vi_tri_bit=2, so_bit=2, gia_tri_moi=0b10)
print(f"Truoc: {bin(gia_tri_hien_tai)}")
print(f"Sau: {bin(gia_tri_moi)}")
Output:
Truoc: 0b110101
Sau: 0b111001
Only 2 bits in the M1:M0 position change (from 01 to 10), every other — bit including the reserved bit — keeps the value read from the device, correct read-modify-write technique.
Common mistakes
- Straight-out a fixed value into the register rather than read-modify-write— as stated, inadvertently overriding the reserved bit or other bit fields being used by the device for another purpose.
- Bit order imprints (bits 0 are LSB or MSB) when reading the— bitmap field most datasheets numberbits 0 as LSB (lowest, rightmost bit in binary representation), but need to confirm firm specific conventions rather than assumptions.
- Standing the offset with the absolute address— as calculated in the Formula section, the offset always needs to be added with the new base address to the real-world address for read/write, not using the offset as the address straight up.
- Non-check of access rights (R/W) before writing— attempts to write to read-only register does not cause obvious errors on many devices, simply has no effect, causing confusion when debugging.
Conclusion
Register map is a specific bridge between datasheet theory and code execution — offset defining addresses, bit field defining the meaning of each bit group, and reserved bit requiring read - modify - write techniques so as not to inadvertently disrupt the internal state of the device. This is the last of the Datasheet Read — series, four that have gone from overall structure, absolute limits, temporal relations, to bit - by - bit detail. The Next Standards & Protocols section expands to the larger-scale — document standardization of industrial robot safety, the ROS2 convention, and related standards.
Get new articles and lessons by email
When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.
Unsubscribe any time with the link in each email. See our Privacy policy.