logo elektroda
logo elektroda
X
logo elektroda

Tuya WiFi Energy Meter PM01_A002 [CBU][BK7231N] HLW8112 SPI Power Reading Ratio 1:5?

kaleidoscopeit 288 3
ADVERTISEMENT
  • #1 21608745
    kaleidoscopeit
    Level 2  
    I'll start a dedicated thread for this device.

    In another thread, a similar power meter is covered, but there'are mixed messages referring
    both devices, causing a little bit of confusion. (https://www.elektroda.com/rtvforum/topic4016609.html)

    The device I'll cover in this thread is the following:

    Tuya WiFi Energy Meter PM01_A002 [CBU][BK7231N] HLW8112 SPI Power Reading Ratio 1:5?   Tuya WiFi Energy Meter PM01_A002 [CBU][BK7231N] HLW8112 SPI Power Reading Ratio 1:5?    Tuya WiFi Energy Meter PM01_A002 [CBU][BK7231N] HLW8112 SPI Power Reading Ratio 1:5?

    Bough from Aliexpress: https://it.aliexpress.com/item/1005007292927857.html

    What are my findings:

    - HLW8112 (https://redmine.laas.fr/attachments/download/3444/DS_HLW8110_HLW8112_EN_Rev1.01%20.pdf)
    - Unstable firmware (at least in my device)
    - Power MeterIC connected directly to CBU module via SPI (NO TuyaMCU)
    - Backup and restore firmware causes wrong measurement, but subsequently I discovered that all power values are reported in a ratio 1:5

    By reading the posts from the other thread I concluded that there is no way to use TuyaMCU driver because the Power Meter IC
    is directly connected to the Tuya module via SPI.

    In fact @dicamarques made an attempt to write a driver for it (21221637#21221637), but, at least with my device,
    by compiling the code he wrote from his GitHub repo, I was unable to get SPI working.

    Furthermore Dicamarques and other guys posted a lot of useful informations:
    - a schematc where you can see that P9 is used for "SCSN"  instead of the standard P15.
    - links where very complete and presumably working drivers can be found

    Subsequently I wanted to try to write my own driver... 
    Spoiler :( I wrote a lot of code, half of it, copy/pasted from the full driver source from the link above, but with no luck... the SPI still not send or receive data.

    This i the link to my repo, in case someone more experienced can tell me what I'm doing wrong :) https://github.com/kaleidoscopeit/OpenBK7231T_App_HLW8112
    (--> To start the driver, issue "startDriver HLW8112SPI" in the command field of the log console in the Web Application)

    It could be that I'm doing something crazy, like buying a logic analyzer and connect it to the SPI in order to understand what goin on when
    the original Tuya firmware speaks with the Power Meter IC.

    I thank the guys who posted in the other thread and I invite everyone to continue in this one.
  • ADVERTISEMENT
  • #2 21609085
    p.kaczmarek2
    Moderator Smart Home
    Interesting, have you seen BL0942 SPI driver in our repository? Maybe it could serve as a reference.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 21610131
    kaleidoscopeit
    Level 2  
    Hi, yes I used it in order to build the base structure and get useful hints on how to write a driver. Thank you.

    I've updated the main topic message with the link to my fork of OpenBK7231T_App.
  • #4 21611254
    p.kaczmarek2
    Moderator Smart Home
    I think you should start with the most basic transmit and read code. Try to choose some register from HLW datasheet and then try to read it with OBK.
    Helpful post? Buy me a coffee.
ADVERTISEMENT