The way this was done is to pull up the datasheet PDF, highlight the relevant table, paste it into a new Wordpad document, edit search and replace and save it as a text document with .js extension.
Here is a portion of the magnetometer address map. Referring to the test in quotes in the following.
Search “ r/w “ and replace with “: 0x”. Other edits apply as well.
Table 22. Magnetic sensor register address map
Registers marked as Reserved must not be changed. Writing to those registers may cause
permanent damage to the device.
To guarantee proper behavior of the device, all registers addresses not listed in the above
table must not be accessed and the content stored on those registers must not be changed.
The content of the registers that are loaded at boot should not be changed. They contain the
factory calibration values. Their content is automatically restored when the device is
powered up.
Name Type
Register address
Default Comment
Hex Binary
Reserved 00 - 04 -- -- Reserved
OFFSET_X_REG_L_M r/w 05 00000000
Offset in order to compensate
environmental effects
OFFSET_X_REG_H_M r/w 06 00000000
OFFSET_Y_REG_L_M r/w 07 00000000
OFFSET_Y_REG_H_M r/w 08 00000000
OFFSET_Z_REG_L_M r/w 09 00000000
OFFSET_Z_REG_H_M r/w 0A 00000000
Reserved 0B - 0E -- -- Reserved
WHO_AM_I_M r 0F 0000 1111 00111101 Magnetic Who I am ID
Reserved 10 - 1F -- -- Reserved
CTRL_REG1_M r/w 20 0010 0000 00010000
A similar process is used to edit the pasted PDF text into the data structure used to bobble the bits.
Each register description in individually cut and pasted to reduce the editing clutter, for example.
8.5 CTRL_REG1_M (20h)
Table 110. X and Y axes operative mode selection
Table 111. Output data rate configuration
Table 107. WHO_AM_I_M register
0 0 1 1 1 1 0 1
Table 108. CTRL_REG1_M register
TEMP_
COMP OM1 OM0 DO2 DO1 DO0 FAST_ODR ST
8.6 CTRL_REG2_M (21h)
8.7 CTRL_REG3_M (22h)
Table 112. CTRL_REG2_M register
0(1)
1. These bits must be set to ‘0’ for the correct operation of the device.
FS1 FS0 0(1) REBOOT SOFT_RST 0(1) 0(1)
I used the bit labels and retained some information as a comment. A portion is shown here:
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
The Magnetometer Bits
The Registers
The way this was done is to pull up the datasheet PDF, highlight the relevant table, paste it into a new Wordpad document, edit search and replace and save it as a text document with .js extension.
Here is a portion of the magnetometer address map. Referring to the test in quotes in the following.
Search “ r/w “ and replace with “: 0x”. Other edits apply as well.
Here is a portion of the edited text
Creating the Data Structure
A similar process is used to edit the pasted PDF text into the data structure used to bobble the bits.
Each register description in individually cut and pasted to reduce the editing clutter, for example.
I used the bit labels and retained some information as a comment. A portion is shown here:
2 Attachments