Expandable-6-Channel-ESP32-Energy-Meter icon indicating copy to clipboard operation
Expandable-6-Channel-ESP32-Energy-Meter copied to clipboard

SPI and reading issues

Open mikelawrence opened this issue 6 months ago • 7 comments

With your recent updates to the ESPHome ATM90E32 component I though it was to time to update to the latest yaml. But I started having serious problems. I started receiving SPI warnings like this one:

[16:55:23][W][atm90e32:863]: [get_phase_current_()] SPI read mismatch: expected 0x0002, got 0x2413

But the real problem was with the data.

Image

Image

What fixed my problem was removing interface: software from 6chan_common.yaml line 55.. This defaults to any and I believe it will choose a hardware SPI on the NodeMCU.

spi:
  interface: software
  clk_pin: 18
  miso_pin: 19
  mosi_pin: 23

mikelawrence avatar May 31 '25 02:05 mikelawrence

Thanks for reporting this!

When you updated things, did you also switch from compiling with the Arduino IDE to ESP-IDF?

CircuitSetup avatar Jun 02 '25 18:06 CircuitSetup

Yes I switched to ESP-IDF. My first configuration was to use your 6chan_common.yaml as a package which switched to ESP-IDF. As you may already know switching platforms requires a physical connection (USB) because the partition table needs to be updated and ESPHome can't do this wirelessly (at least not yet).

mikelawrence avatar Jun 02 '25 20:06 mikelawrence

Wait a sec. I thought the advice was the other way around to switch to arduino from esp-idf. The latest common file now references type arduino instead of esp-idf

rykm48 avatar Jun 10 '25 04:06 rykm48

Wait a sec. I thought the advice was the other way around to switch to arduino from esp-idf. The latest common file now references type arduino instead of esp-idf

If you have more than 2 add-on boards, it's necessary to use the Arduino framework using the default spi config (which is interface: any). Hardware SPI on the esp-idf can't have more than 6 devices, and software SPI produces the results above. I'm not sure why this is happening yet.

CircuitSetup avatar Jun 10 '25 13:06 CircuitSetup

Hardware SPI on the esp-idf can't have more than 6 devices

See https://github.com/esphome/esphome/pull/9128#issuecomment-2983430390 for a fix.

clydebarrow avatar Jun 18 '25 10:06 clydebarrow

Hardware SPI on the esp-idf can't have more than 6 devices

See esphome/esphome#9128 (comment) for a fix.

Thank you so much! This is working great!

For others seeing this, if you want to use the ESP-IDF with more than 2 add-on boards you'll need to add

external_components:
  - source: github://pr#9128
    components: [mipi_spi, spi]
    refresh: 1h

to your config until the PR gets pushed to release

with

esp32:
  framework:
    type: esp-idf
spi:
  interface: hardware

and release_device: true under each - platform: atm90e32

CircuitSetup avatar Jun 18 '25 14:06 CircuitSetup

Hardware SPI on the esp-idf can't have more than 6 devices

this is now in the latest release, 2025.7.0. All configs have been updated to reflect this and also include the optional addition of other config setups: https://github.com/CircuitSetup/Expandable-6-Channel-ESP32-Energy-Meter/tree/master/Software/ESPHome

CircuitSetup avatar Jul 16 '25 14:07 CircuitSetup