MMC56x3 offset+mG

This commit is contained in:
leo 2022-12-20 14:05:14 +01:00
parent 65da56d15a
commit 92d36acb47
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB
3 changed files with 36 additions and 3 deletions

View File

@ -67,4 +67,26 @@ esp_err_t MMC56x3_reset(){
uint8_t set = 1 << DO_RESET;
ESP_ERROR_CHECK(i2c_write_reg(IC0, &set, 1));
return ESP_OK;
}
esp_err_t MMC56x3_get_bridge_offset(int32_t* x, int32_t* y, int32_t* z){
MMC56x3_set();
int32_t vbx, vby, vbz;
MMC56x3_get_mag_field(&vbx, &vby, &vbz);
*x=vbx;
*y=vby;
*z=vbz;
MMC56x3_reset();
MMC56x3_get_mag_field(&vbx, &vby, &vbz);
*x=(*x+vbx)/2;
*y=(*y+vby)/2;
*z=(*z+vbz)/2;
return ESP_OK;
}
esp_err_t MMC56x3_to_mG(int32_t x, int32_t y, int32_t z, float* rx, float* ry, float* rz){
*rx = x*0.0625;
*ry = y*0.0625;
*rz = z*0.0625;
return ESP_OK;
}

View File

@ -7,4 +7,8 @@ esp_err_t MMC56x3_get_temperature(uint8_t* temp);
esp_err_t MMC56x3_get_mag_field(int32_t* x, int32_t* y, int32_t* z);
esp_err_t MMC56x3_set();
esp_err_t MMC56x3_reset();
esp_err_t MMC56x3_reset();
esp_err_t MMC56x3_get_bridge_offset(int32_t* x, int32_t* y, int32_t* z);
esp_err_t MMC56x3_to_mG(int32_t x, int32_t y, int32_t z, float* rx, float* ry, float* rz);

View File

@ -68,8 +68,12 @@ void app_main(void){
MMC56x3_get_product_ID(&id);
uint8_t temp;
MMC56x3_get_temperature(&temp);
int32_t offx, offy, offz;
MMC56x3_get_bridge_offset(&offx, &offy, &offz);
MMC56x3_set();
ESP_LOGI("MAIN", "MMC5603 product id %d", id);
ESP_LOGI("MAIN", "MMC measured temp is %d", temp);
ESP_LOGI("MAIN", "MMC bridge offset; x %ld, y %ld, z %ld", offx, offy, offz);
init_scd4x();
scd4x_power_down();
@ -89,9 +93,12 @@ void app_main(void){
}
while(1){
/*int32_t x,y,z;
int32_t x,y,z;
MMC56x3_get_mag_field(&x, &y, &z);
ESP_LOGI("MAIN", "BField x %ld, y %ld, z %ld", x, y, z);*/
float bx, by, bz;
MMC56x3_to_mG(x, y, z, &bx, &by, &bz);
ESP_LOGI("MAIN", "BField x %ld, y %ld, z %ld", x, y, z);
ESP_LOGI("MAIN", "BField x %f mG, y %f mG, z %f mG", bx, by, bz);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}