8 static const char *
const TAG =
"atm90e26";
11 if (this->
read16_(ATM90E26_REGISTER_FUNCEN) != 0x0030) {
44 ESP_LOGCONFIG(TAG,
"Setting up ATM90E26 Component...");
47 uint16_t mmode = 0x422;
51 this->
write16_(ATM90E26_REGISTER_SOFTRESET, 0x789A);
52 this->
write16_(ATM90E26_REGISTER_FUNCEN,
54 uint16_t read = this->
read16_(ATM90E26_REGISTER_LASTDATA);
56 ESP_LOGW(TAG,
"Could not initialize ATM90E26 IC, check SPI settings: %d", read);
61 this->
write16_(ATM90E26_REGISTER_SAGTH, 0x17DD);
64 this->
write16_(ATM90E26_REGISTER_CALSTART, 0x5678);
67 this->
write16_(ATM90E26_REGISTER_MMODE, mmode);
74 this->
write16_(ATM90E26_REGISTER_LPHI, 0x0000);
75 this->
write16_(ATM90E26_REGISTER_NGAIN, 0x0000);
76 this->
write16_(ATM90E26_REGISTER_NPHI, 0x0000);
77 this->
write16_(ATM90E26_REGISTER_PSTARTTH, 0x08BD);
78 this->
write16_(ATM90E26_REGISTER_PNOLTH, 0x0000);
79 this->
write16_(ATM90E26_REGISTER_QSTARTTH, 0x0AEC);
80 this->
write16_(ATM90E26_REGISTER_QNOLTH, 0x0000);
93 this->
write16_(ATM90E26_REGISTER_CS1, cs);
94 ESP_LOGVV(TAG,
"Set CS1 to: 0x%04X", cs);
97 this->
write16_(ATM90E26_REGISTER_ADJSTART, 0x5678);
100 this->
write16_(ATM90E26_REGISTER_IGAINN, 0x7530);
101 this->
write16_(ATM90E26_REGISTER_UOFFSET, 0x0000);
102 this->
write16_(ATM90E26_REGISTER_IOFFSETL, 0x0000);
103 this->
write16_(ATM90E26_REGISTER_IOFFSETN, 0x0000);
104 this->
write16_(ATM90E26_REGISTER_POFFSETL, 0x0000);
105 this->
write16_(ATM90E26_REGISTER_QOFFSETL, 0x0000);
106 this->
write16_(ATM90E26_REGISTER_POFFSETN, 0x0000);
107 this->
write16_(ATM90E26_REGISTER_QOFFSETN, 0x0000);
112 this->
write16_(ATM90E26_REGISTER_CS2, cs);
113 ESP_LOGVV(TAG,
"Set CS2 to: 0x%04X", cs);
115 this->
write16_(ATM90E26_REGISTER_CALSTART,
117 this->
write16_(ATM90E26_REGISTER_ADJSTART,
120 const uint16_t sys_status = this->
read16_(ATM90E26_REGISTER_SYSSTATUS);
121 if (sys_status & 0xC000) {
123 ESP_LOGW(TAG,
"Could not initialize ATM90E26 IC: CS1 was incorrect, expected: 0x%04X",
124 this->
read16_(ATM90E26_REGISTER_CS1));
127 if (sys_status & 0x3000) {
128 ESP_LOGW(TAG,
"Could not initialize ATM90E26 IC: CS2 was incorrect, expected: 0x%04X",
129 this->
read16_(ATM90E26_REGISTER_CS2));
135 ESP_LOGCONFIG(
"",
"ATM90E26:");
136 LOG_PIN(
" CS Pin: ", this->
cs_);
138 ESP_LOGE(TAG,
"Communication with ATM90E26 failed!");
140 LOG_UPDATE_INTERVAL(
this);
163 output = (uint16_t(data[0] & 0xFF) << 8) | (data[1] & 0xFF);
164 ESP_LOGVV(TAG,
"read16_ 0x%04X output 0x%04X", a_register, output);
169 ESP_LOGVV(TAG,
"write16_ 0x%04X val 0x%04X", a_register, val);
180 const uint16_t current = this->
read16_(ATM90E26_REGISTER_IRMS);
181 return current / 1000.0f;
185 const uint16_t voltage = this->
read16_(ATM90E26_REGISTER_URMS);
186 return voltage / 100.0f;
190 const int16_t
val = this->
read16_(ATM90E26_REGISTER_PMEAN);
195 const int16_t
val = this->
read16_(ATM90E26_REGISTER_QMEAN);
200 const uint16_t
val = this->
read16_(ATM90E26_REGISTER_POWERF);
202 return -(val & 0x7FF) / 1000.0f;
204 return val / 1000.0f;
209 const uint16_t
val = this->
read16_(ATM90E26_REGISTER_APENERGY);
220 const uint16_t
val = this->
read16_(ATM90E26_REGISTER_ANENERGY);
230 const uint16_t freq = this->
read16_(ATM90E26_REGISTER_FREQ);
231 return freq / 100.0f;
const float DATA
For components that import data from directly connected sensors like DHT.
float get_reactive_power_()
float get_forward_active_energy_()
sensor::Sensor * current_sensor_
sensor::Sensor * power_sensor_
void status_set_warning(const char *message="unspecified")
sensor::Sensor * freq_sensor_
void spi_setup() override
sensor::Sensor * reactive_power_sensor_
void write_byte(uint8_t data)
void write16_(uint8_t a_register, uint16_t val)
float get_line_current_()
void read_array(uint8_t *data, size_t length)
void status_clear_warning()
float get_line_voltage_()
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * forward_active_energy_sensor_
void dump_config() override
float get_active_power_()
float get_setup_priority() const override
uint16_t read16_(uint8_t a_register)
sensor::Sensor * voltage_sensor_
float get_power_factor_()
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
sensor::Sensor * power_factor_sensor_
float get_reverse_active_energy_()
uint32_t cumulative_reverse_active_energy_
uint32_t cumulative_forward_active_energy_
sensor::Sensor * reverse_active_energy_sensor_