10void ATM90E26Component::update() {
11 if (this->
read16_(ATM90E26_REGISTER_FUNCEN) != 0x0030) {
30 uint16_t mmode = 0x422;
34 this->
write16_(ATM90E26_REGISTER_SOFTRESET, 0x789A);
35 this->
write16_(ATM90E26_REGISTER_FUNCEN,
37 uint16_t read = this->
read16_(ATM90E26_REGISTER_LASTDATA);
39 ESP_LOGW(TAG,
"Could not initialize ATM90E26 IC, check SPI settings: %d", read);
44 this->
write16_(ATM90E26_REGISTER_SAGTH, 0x17DD);
47 this->
write16_(ATM90E26_REGISTER_CALSTART, 0x5678);
50 this->
write16_(ATM90E26_REGISTER_MMODE, mmode);
57 this->
write16_(ATM90E26_REGISTER_LPHI, 0x0000);
58 this->
write16_(ATM90E26_REGISTER_NGAIN, 0x0000);
59 this->
write16_(ATM90E26_REGISTER_NPHI, 0x0000);
60 this->
write16_(ATM90E26_REGISTER_PSTARTTH, 0x08BD);
61 this->
write16_(ATM90E26_REGISTER_PNOLTH, 0x0000);
62 this->
write16_(ATM90E26_REGISTER_QSTARTTH, 0x0AEC);
63 this->
write16_(ATM90E26_REGISTER_QNOLTH, 0x0000);
76 this->
write16_(ATM90E26_REGISTER_CS1, cs);
77 ESP_LOGVV(TAG,
"Set CS1 to: 0x%04X", cs);
80 this->
write16_(ATM90E26_REGISTER_ADJSTART, 0x5678);
83 this->
write16_(ATM90E26_REGISTER_IGAINN, 0x7530);
84 this->
write16_(ATM90E26_REGISTER_UOFFSET, 0x0000);
85 this->
write16_(ATM90E26_REGISTER_IOFFSETL, 0x0000);
86 this->
write16_(ATM90E26_REGISTER_IOFFSETN, 0x0000);
87 this->
write16_(ATM90E26_REGISTER_POFFSETL, 0x0000);
88 this->
write16_(ATM90E26_REGISTER_QOFFSETL, 0x0000);
89 this->
write16_(ATM90E26_REGISTER_POFFSETN, 0x0000);
90 this->
write16_(ATM90E26_REGISTER_QOFFSETN, 0x0000);
95 this->
write16_(ATM90E26_REGISTER_CS2, cs);
96 ESP_LOGVV(TAG,
"Set CS2 to: 0x%04X", cs);
98 this->
write16_(ATM90E26_REGISTER_CALSTART,
100 this->
write16_(ATM90E26_REGISTER_ADJSTART,
103 const uint16_t sys_status = this->
read16_(ATM90E26_REGISTER_SYSSTATUS);
104 if (sys_status & 0xC000) {
106 ESP_LOGW(TAG,
"Could not initialize ATM90E26 IC: CS1 was incorrect, expected: 0x%04X",
107 this->
read16_(ATM90E26_REGISTER_CS1));
110 if (sys_status & 0x3000) {
111 ESP_LOGW(TAG,
"Could not initialize ATM90E26 IC: CS2 was incorrect, expected: 0x%04X",
112 this->
read16_(ATM90E26_REGISTER_CS2));
117void ATM90E26Component::dump_config() {
118 ESP_LOGCONFIG(
"",
"ATM90E26:");
119 LOG_PIN(
" CS Pin: ", this->
cs_);
120 LOG_UPDATE_INTERVAL(
this);
121 LOG_SENSOR(
" ",
"Voltage A", this->voltage_sensor_);
122 LOG_SENSOR(
" ",
"Current A", this->current_sensor_);
123 LOG_SENSOR(
" ",
"Power A", this->power_sensor_);
124 LOG_SENSOR(
" ",
"Reactive Power A", this->reactive_power_sensor_);
125 LOG_SENSOR(
" ",
"PF A", this->power_factor_sensor_);
126 LOG_SENSOR(
" ",
"Active Forward Energy A", this->forward_active_energy_sensor_);
127 LOG_SENSOR(
" ",
"Active Reverse Energy A", this->reverse_active_energy_sensor_);
128 LOG_SENSOR(
" ",
"Frequency", this->freq_sensor_);
143 ESP_LOGVV(TAG,
"read16_ 0x%04X output 0x%04X", a_register, output);
148 ESP_LOGVV(TAG,
"write16_ 0x%04X val 0x%04X", a_register,
val);
159 const uint16_t current = this->
read16_(ATM90E26_REGISTER_IRMS);
160 return current / 1000.0f;
164 const uint16_t voltage = this->
read16_(ATM90E26_REGISTER_URMS);
165 return voltage / 100.0f;
169 const int16_t
val = this->
read16_(ATM90E26_REGISTER_PMEAN);
174 const int16_t
val = this->
read16_(ATM90E26_REGISTER_QMEAN);
179 const uint16_t
val = this->
read16_(ATM90E26_REGISTER_POWERF);
181 return -(
val & 0x7FFF) / 1000.0f;
183 return val / 1000.0f;
188 const uint16_t
val = this->
read16_(ATM90E26_REGISTER_APENERGY);
199 const uint16_t
val = this->
read16_(ATM90E26_REGISTER_ANENERGY);
209 const uint16_t freq = this->
read16_(ATM90E26_REGISTER_FREQ);
210 return freq / 100.0f;