MMC56x3 temp
This commit is contained in:
parent
67233261a3
commit
ed23d0e97f
@ -1,10 +1,17 @@
|
|||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "MMC56x3.h"
|
#include "MMC56x3.h"
|
||||||
#include "MMC56x3_hal.h"
|
#include "MMC56x3_hal.h"
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
#define PRODUCT_ID_1 0x39
|
#define PRODUCT_ID_1 0x39
|
||||||
#define TEMPERATURE 0x09
|
#define TEMPERATURE 0x09
|
||||||
|
#define IC0 0x1B
|
||||||
|
#define STATUS1 0x18
|
||||||
|
|
||||||
|
#define TAKE_MEAS_T 1
|
||||||
|
#define MEAS_T_DONE 7
|
||||||
|
|
||||||
esp_err_t MMC56x3_get_product_ID(uint8_t* id){
|
esp_err_t MMC56x3_get_product_ID(uint8_t* id){
|
||||||
ESP_ERROR_CHECK(i2c_read_reg(PRODUCT_ID_1, id, 1));
|
ESP_ERROR_CHECK(i2c_read_reg(PRODUCT_ID_1, id, 1));
|
||||||
@ -12,6 +19,15 @@ esp_err_t MMC56x3_get_product_ID(uint8_t* id){
|
|||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t MMC56x3_get_temperature(uint8_t* temp){
|
esp_err_t MMC56x3_get_temperature(uint8_t* temp){
|
||||||
|
uint8_t startMeas = 1<<TAKE_MEAS_T;
|
||||||
|
ESP_ERROR_CHECK(i2c_write_reg(IC0, &startMeas, 1));
|
||||||
|
for(int i=0; i<5; i++){ // wait for meas_t_done
|
||||||
|
uint8_t status1_content;
|
||||||
|
ESP_ERROR_CHECK(i2c_read_reg(STATUS1, &status1_content, 1));
|
||||||
|
ESP_LOGI("MMC56x3", "status 1 %d", status1_content);
|
||||||
|
if(status1_content & (1 << MEAS_T_DONE)) break;
|
||||||
|
i2c_hal_wait_ms(1);
|
||||||
|
}
|
||||||
ESP_ERROR_CHECK(i2c_read_reg(TEMPERATURE, temp, 1));
|
ESP_ERROR_CHECK(i2c_read_reg(TEMPERATURE, temp, 1));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
@ -2,6 +2,7 @@
|
|||||||
#include "driver/i2c.h"
|
#include "driver/i2c.h"
|
||||||
|
|
||||||
#include "MMC56x3_hal.h"
|
#include "MMC56x3_hal.h"
|
||||||
|
#include "freertos/portmacro.h"
|
||||||
#include "hal/i2c_types.h"
|
#include "hal/i2c_types.h"
|
||||||
|
|
||||||
#define MMC56x3_I2C_ADDRESS 0x30
|
#define MMC56x3_I2C_ADDRESS 0x30
|
||||||
@ -13,6 +14,16 @@ esp_err_t i2c_read_reg(uint8_t address, uint8_t* data, uint16_t count){
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_err_t i2c_write_reg(uint8_t address, uint8_t* data, uint16_t count){
|
||||||
|
esp_err_t err=ESP_OK;
|
||||||
|
uint8_t buff[count+1];
|
||||||
|
buff[0]=address;
|
||||||
|
for(int i=0; i<count; i++) buff[i+1]=data[i];
|
||||||
|
i2c_write(&buff, count+1);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
esp_err_t i2c_read(uint8_t* data, uint16_t count){
|
esp_err_t i2c_read(uint8_t* data, uint16_t count){
|
||||||
i2c_cmd_handle_t cmdLnk = i2c_cmd_link_create();
|
i2c_cmd_handle_t cmdLnk = i2c_cmd_link_create();
|
||||||
esp_err_t err = ESP_OK;
|
esp_err_t err = ESP_OK;
|
||||||
@ -36,4 +47,8 @@ esp_err_t i2c_write(const uint8_t* data, uint16_t count){
|
|||||||
i2c_master_cmd_begin(I2C_NUM_0,cmdLnk,1000 / portTICK_PERIOD_MS); /* TODO:non const port */
|
i2c_master_cmd_begin(I2C_NUM_0,cmdLnk,1000 / portTICK_PERIOD_MS); /* TODO:non const port */
|
||||||
i2c_cmd_link_delete(cmdLnk);
|
i2c_cmd_link_delete(cmdLnk);
|
||||||
return err;
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
void i2c_hal_wait_ms(uint16_t len){
|
||||||
|
vTaskDelay(len / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
@ -1,4 +1,8 @@
|
|||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
esp_err_t i2c_read_reg(uint8_t address, uint8_t* data, uint16_t count);
|
esp_err_t i2c_read_reg(uint8_t address, uint8_t* data, uint16_t count);
|
||||||
|
esp_err_t i2c_write_reg(uint8_t address, uint8_t* data, uint16_t count);
|
||||||
|
|
||||||
esp_err_t i2c_read(uint8_t* data, uint16_t count);
|
esp_err_t i2c_read(uint8_t* data, uint16_t count);
|
||||||
esp_err_t i2c_write(const uint8_t* data, uint16_t count);
|
esp_err_t i2c_write(const uint8_t* data, uint16_t count);
|
||||||
|
|
||||||
|
void i2c_hal_wait_ms(uint16_t len);
|
@ -45,7 +45,7 @@ void app_main(void){
|
|||||||
.min_freq_mhz = 40,
|
.min_freq_mhz = 40,
|
||||||
.light_sleep_enable = true, // enable light sleep
|
.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));
|
configuration_data_t* conf = malloc(sizeof(configuration_data_t));
|
||||||
@ -59,14 +59,18 @@ void app_main(void){
|
|||||||
|
|
||||||
// start sensor
|
// start sensor
|
||||||
init_i2c();
|
init_i2c();
|
||||||
init_scd4x();
|
|
||||||
|
|
||||||
init_battery_level_adc(conf->battery_conf);
|
init_battery_level_adc(conf->battery_conf);
|
||||||
|
|
||||||
uint8_t id=0;
|
uint8_t id=0;
|
||||||
MMC56x3_get_product_ID(&id);
|
MMC56x3_get_product_ID(&id);
|
||||||
|
uint8_t temp;
|
||||||
|
MMC56x3_get_temperature(&temp);
|
||||||
ESP_LOGI("MAIN", "MMC5603 product id %d", id);
|
ESP_LOGI("MAIN", "MMC5603 product id %d", id);
|
||||||
|
ESP_LOGI("MAIN", "MMC measured temp is %d", temp);
|
||||||
|
|
||||||
|
init_scd4x();
|
||||||
|
scd4x_power_down();
|
||||||
switch(conf->sensor->mode){
|
switch(conf->sensor->mode){
|
||||||
case SCD4X_NORMAL_MODE:
|
case SCD4X_NORMAL_MODE:
|
||||||
ESP_ERROR_CHECK(scd4x_start_periodic_measurement());
|
ESP_ERROR_CHECK(scd4x_start_periodic_measurement());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user