8000 Merge pull request #3 from Scalpel78/patch-1 · esp32vn/esp32-snippets@79c382a · GitHub
[go: up one dir, main page]

Skip to content

Commit 79c382a

Browse files
authored
Merge pull request nkolban#3 from Scalpel78/patch-1
Register comments
2 parents 6d25120 + d6db700 commit 79c382a

File tree

1 file changed

+17
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,32 @@ void task_hmc5883l(void *ignore) {
3232
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
3333
i2c_master_start(cmd);
3434
i2c_master_write_byte(cmd, (I2C_ADDRESS << 1) | I2C_MASTER_WRITE, 1);
35-
i2c_master_write_byte(cmd, 0x02, 1); // Mode register
36-
i2c_master_write_byte(cmd, 0x00, 1); // value 0
35+
i2c_master_write_byte(cmd, 0x02, 1); // 0x02 = "Mode register"
36+
i2c_master_write_byte(cmd, 0x00, 1); // 0x00 = "Continuous-Measurement Mode"
3737
i2c_master_stop(cmd);
3838
i2c_master_cmd_begin(I2C_NUM_0, cmd, 1000/portTICK_PERIOD_MS);
3939
i2c_cmd_link_delete(cmd);
4040

41+
//Set value in "Configuration Register B"
4142
cmd = i2c_cmd_link_create();
4243
i2c_master_start(cmd);
4344
i2c_master_write_byte(cmd, (I2C_ADDRESS << 1) | I2C_MASTER_WRITE, 1);
44-
i2c_master_write_byte(cmd, 0x01, 1); // Mode register
45-
i2c_master_write_byte(cmd, 0x20, 1); // value 0
45+
i2c_master_write_byte(cmd, 0x01, 1); // 0x01 = "Configuration Register B"
46+
i2c_master_write_byte(cmd, 0x20, 1); // 0x20 = default Gain setting
4647
i2c_master_stop(cmd);
4748
i2c_master_cmd_begin(I2C_NUM_0, cmd, 1000/portTICK_PERIOD_MS);
4849
i2c_cmd_link_delete(cmd);
4950

51+
//Set active register to "Identification Register A"
5052
cmd = i2c_cmd_link_create();
5153
ESP_ERROR_CHECK(i2c_master_start(cmd));
5254
ESP_ERROR_CHECK(i2c_master_write_byte(cmd, (I2C_ADDRESS << 1) | I2C_MASTER_WRITE, 1));
53-
ESP_ERROR_CHECK(i2c_master_write_byte(cmd, 10, 1)); // Data registers
55+
ESP_ERROR_CHECK(i2c_master_write_byte(cmd, 10, 1)); //10 = 0x0A = "Identification Register A"
5456
ESP_ERROR_CHECK(i2c_master_stop(cmd));
5557
ESP_ERROR_CHECK(i2c_master_cmd_begin(I2C_NUM_0, cmd, 100/portTICK_PERIOD_MS));
5658
i2c_cmd_link_delete(cmd);
5759

60+
//Get data from Identification Register A, B and C
5861
cmd = i2c_cmd_link_create();
5962
ESP_ERROR_CHECK(i2c_master_start(cmd));
6063
ESP_ERROR_CHECK(i2c_master_write_byte(cmd, (I2C_ADDRESS << 1) | I2C_MASTER_READ, 1));
@@ -66,23 +69,25 @@ void task_hmc5883l(void *ignore) {
6669
i2c_cmd_link_delete(cmd);
6770

6871
while(1) {
72+
//Set active registert to "Data Output X MSB Register"
6973
cmd = i2c_cmd_link_create();
7074
i2c_master_start(cmd);
7175
i2c_master_write_byte(cmd, (I2C_ADDRESS << 1) | I2C_MASTER_WRITE, 1);
72-
i2c_master_write_byte(cmd, 0x03, 1); // Data registers
76+
i2c_master_write_byte(cmd, 0x03, 1); //0x03 = "Data Output X MSB Register"
7377
i2c_master_stop(cmd);
7478
i2c_master_cmd_begin(I2C_NUM_0, cmd, 1000/portTICK_PERIOD_MS);
7579
i2c_cmd_link_delete(cmd);
7680

81+
//Read values for X, Y and Z
7782
cmd = i2c_cmd_link_create();
7883
i2c_master_start(cmd);
7984
i2c_master_write_byte(cmd, (I2C_ADDRESS << 1) | I2C_MASTER_READ, 1);
80
81-
i2c_master_read_byte(cmd, data+1, 0);
82-
i2c_master_read_byte(cmd, data+2, 0);
83-
i2c_master_read_byte(cmd, data+3, 0);
84-
i2c_master_read_byte(cmd, data+4, 0);
85-
i2c_master_read_byte(cmd, data+5, 1);
85+
i2c_master_read_byte(cmd, data, 0); //"Data Output X MSB Register"
86+
i2c_master_read_byte(cmd, data+1, 0); //"Data Output X LSB Register"
87+
i2c_master_read_byte(cmd, data+2, 0); //"Data Output Z MSB Register"
88+
i2c_master_read_byte(cmd, data+3, 0); //"Data Output Z LSB Register"
89+
i2c_master_read_byte(cmd, data+4, 0); //"Data Output Y MSB Register"
90+
i2c_master_read_byte(cmd, data+5, 1); //"Data Output Y LSB Register "
8691
i2c_master_stop(cmd);
8792
i2c_master_cmd_begin(I2C_NUM_0, cmd, 1000/portTICK_PERIOD_MS);
8893
i2c_cmd_link_delete(cmd);