ESPHome  2024.3.1
mcp3204.cpp
Go to the documentation of this file.
1 #include "mcp3204.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace mcp3204 {
6 
7 static const char *const TAG = "mcp3204";
8 
10 
12  ESP_LOGCONFIG(TAG, "Setting up mcp3204");
13  this->spi_setup();
14 }
15 
17  ESP_LOGCONFIG(TAG, "MCP3204:");
18  LOG_PIN(" CS Pin:", this->cs_);
19  ESP_LOGCONFIG(TAG, " Reference Voltage: %.2fV", this->reference_voltage_);
20 }
21 
22 float MCP3204::read_data(uint8_t pin) {
23  uint8_t adc_primary_config = 0b00000110 | (pin >> 2);
24  uint8_t adc_secondary_config = pin << 6;
25  this->enable();
26  this->transfer_byte(adc_primary_config);
27  uint8_t adc_primary_byte = this->transfer_byte(adc_secondary_config);
28  uint8_t adc_secondary_byte = this->transfer_byte(0x00);
29  this->disable();
30  uint16_t digital_value = (adc_primary_byte << 8 | adc_secondary_byte) & 0b111111111111;
31  return float(digital_value) / 4096.000 * this->reference_voltage_;
32 }
33 
34 } // namespace mcp3204
35 } // namespace esphome
float read_data(uint8_t pin)
Definition: mcp3204.cpp:22
void dump_config() override
Definition: mcp3204.cpp:16
float get_setup_priority() const override
Definition: mcp3204.cpp:9
GPIOPin * cs_
Definition: spi.h:395
void setup() override
Definition: mcp3204.cpp:11
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:18
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7