From 65da56d15ac70e25a9a9d58e49a5d7f8c6b9474b Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 20 Dec 2022 12:00:27 +0100 Subject: [PATCH] MMC56x3 mag+set/reset --- components/MMC56x3/MMC56x3.c | 39 +++++++++++++++++++++++++++- components/MMC56x3/include/MMC56x3.h | 9 ++++++- main/CO2_Sense.c | 9 +++++-- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/components/MMC56x3/MMC56x3.c b/components/MMC56x3/MMC56x3.c index 8ac03b3..fbd124c 100644 --- a/components/MMC56x3/MMC56x3.c +++ b/components/MMC56x3/MMC56x3.c @@ -9,9 +9,15 @@ #define TEMPERATURE 0x09 #define IC0 0x1B #define STATUS1 0x18 +#define XOUT0 0x00 +#define XOUT2 0x06 #define TAKE_MEAS_T 1 #define MEAS_T_DONE 7 +#define TAKE_MEAS_M 0 +#define MEAS_M_DONE 6 +#define DO_SET 3 +#define DO_RESET 4 esp_err_t MMC56x3_get_product_ID(uint8_t* id){ ESP_ERROR_CHECK(i2c_read_reg(PRODUCT_ID_1, id, 1)); @@ -19,7 +25,7 @@ esp_err_t MMC56x3_get_product_ID(uint8_t* id){ } esp_err_t MMC56x3_get_temperature(uint8_t* temp){ - uint8_t startMeas = 1<> 4); + *y=(buff[2] << 12) | (buff[3] << 4) | (buff[7] >> 4); + *z=(buff[4] << 12) | (buff[5] << 4) | (buff[8] >> 4); + *x-=1 << 19; + *y-=1 << 19; + *z-=1 << 19; + return ESP_OK; +} + +esp_err_t MMC56x3_set(){ + uint8_t set = 1 << DO_SET; + ESP_ERROR_CHECK(i2c_write_reg(IC0, &set, 1)); + return ESP_OK; +} +esp_err_t MMC56x3_reset(){ + uint8_t set = 1 << DO_RESET; + ESP_ERROR_CHECK(i2c_write_reg(IC0, &set, 1)); + return ESP_OK; } \ No newline at end of file diff --git a/components/MMC56x3/include/MMC56x3.h b/components/MMC56x3/include/MMC56x3.h index 16a9ed3..dd6e13b 100644 --- a/components/MMC56x3/include/MMC56x3.h +++ b/components/MMC56x3/include/MMC56x3.h @@ -1,3 +1,10 @@ #include "esp_err.h" +#include + esp_err_t MMC56x3_get_product_ID(uint8_t* id); -esp_err_t MMC56x3_get_temperature(uint8_t* temp); \ No newline at end of file +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(); \ No newline at end of file diff --git a/main/CO2_Sense.c b/main/CO2_Sense.c index 8c73f37..90828c2 100644 --- a/main/CO2_Sense.c +++ b/main/CO2_Sense.c @@ -45,7 +45,7 @@ void app_main(void){ .min_freq_mhz = 40, .light_sleep_enable = true, // enable light sleep }; - //ESP_ERROR_CHECK(esp_pm_configure(&pm_config)); + ESP_ERROR_CHECK(esp_pm_configure(&pm_config)); configuration_data_t* conf = malloc(sizeof(configuration_data_t)); @@ -61,7 +61,9 @@ void app_main(void){ init_i2c(); init_battery_level_adc(conf->battery_conf); - + + MMC56x3_set(); + MMC56x3_reset(); uint8_t id=0; MMC56x3_get_product_ID(&id); uint8_t temp; @@ -87,6 +89,9 @@ void app_main(void){ } while(1){ + /*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);*/ vTaskDelay(1000 / portTICK_PERIOD_MS); } }