diff --git a/main/EMC2101.c b/main/EMC2101.c index fdee10e..9a50727 100644 --- a/main/EMC2101.c +++ b/main/EMC2101.c @@ -35,8 +35,10 @@ static esp_err_t register_write_byte(uint8_t reg_addr, uint8_t data) { //takes a fan speed percent -void EMC2101_set_config(uint8_t reg) { - ESP_ERROR_CHECK(register_write_byte(EMC2101_REG_CONFIG, reg)); +void EMC2101_init(void) { + + //set the TACH input + ESP_ERROR_CHECK(register_write_byte(EMC2101_REG_CONFIG, 0x04)); } //takes a fan speed percent @@ -65,10 +67,24 @@ uint16_t EMC2101_get_fan_speed(void) { return RPM; } -void EMC2101_read(void) { - uint8_t data; +// void EMC2101_read(void) { +// uint8_t data; - /* Read the EMC2101 WHO_AM_I register, on power up the register should have the value 0x16 or 0x28 */ - ESP_ERROR_CHECK(register_read(EMC2101_REG_CONFIG, &data, 1)); - ESP_LOGI(TAG, "EMC2101 Config register = 0x%02X", data); +// /* Read the EMC2101 WHO_AM_I register, on power up the register should have the value 0x16 or 0x28 */ +// ESP_ERROR_CHECK(register_read(EMC2101_REG_CONFIG, &data, 1)); +// ESP_LOGI(TAG, "EMC2101 Config register = 0x%02X", data); +// } + +float EMC2101_get_chip_temp(void) { + uint8_t temp_msb, temp_lsb; + uint16_t reading; + + + ESP_ERROR_CHECK(register_read(EMC2101_EXTERNAL_TEMP_MSB, &temp_msb, 1)); + ESP_ERROR_CHECK(register_read(EMC2101_EXTERNAL_TEMP_LSB, &temp_lsb, 1)); + + reading = temp_lsb | (temp_msb << 8); + reading >>= 5; + + return (float)reading / 8.0; } \ No newline at end of file diff --git a/main/EMC2101.h b/main/EMC2101.h index c9879a3..5971795 100644 --- a/main/EMC2101.h +++ b/main/EMC2101.h @@ -57,8 +57,9 @@ typedef enum { } emc2101_rate_t; void EMC2101_set_fan_speed(float); -void EMC2101_read(void); +//void EMC2101_read(void); uint16_t EMC2101_get_fan_speed(void); -void EMC2101_set_config(uint8_t); +void EMC2101_init(void); +float EMC2101_get_chip_temp(void); #endif /* EMC2101_H_ */ \ No newline at end of file diff --git a/main/i2c_simple_main.c b/main/i2c_simple_main.c index 831b857..221db61 100755 --- a/main/i2c_simple_main.c +++ b/main/i2c_simple_main.c @@ -46,11 +46,11 @@ void app_main(void) { DS4432U_set_vcore(1.25); //Fan Tests - EMC2101_set_config(0x04); //set the tach input - EMC2101_read(); + EMC2101_init(); EMC2101_set_fan_speed(0.5); vTaskDelay(500 / portTICK_RATE_MS); ESP_LOGI(TAG, "Fan Speed: %d RPM", EMC2101_get_fan_speed()); + ESP_LOGI(TAG, "Chip Temp: %.2f C", EMC2101_get_chip_temp()); //Current Sensor tests ESP_LOGI(TAG, "Current: %d mA", INA260_read_current());