Search code examples
pythonraspberry-pi3spidev

Decoding the received data from ATM90E32AS energy meter IC


I wrote a python code (raspberry pi) to receive voltage, current and power values from ATM90E32AS energy meter IC. Iam using spidev library for SPI communication with the energy meter IC. I initialized two bytearrays (each 4 bytes wide) for reading and writing the energy meter IC like

writeBuffer = bytearray ([0x00,0x00,0x00,0x00])
readBuffer = bytearray ([0x00,0x00,0x00,0x00]) 

For example reading active R phase voltage i initialized the register values like

VrRead_Reg = bytearray ([0x80, 0xD9])

And i try to write the above value to the IC using following subroutine to read the R phase voltage

def Vr_read():
    writeBuffer[0] = VrRead_Reg[0]
    writeBuffer[1] = VrRead_Reg[1]
    #print(writeBuffer)
    readBuffer = spi.xfer(writeBuffer)
    print("Vr:",readBuffer)
    time.sleep(0.5)

And iam getting the output like

Vr: [255,255,89,64]
Vr: [255,255,89,170]
Vr: [255,255,89,220]
Vr: [255,255,89,1]
Vr: [255,255,89,10]

I measured the voltage at mains it shows 230V. Then i try to match the above output with the measured voltage. Here the third byte 89 corresponds to 230V. Then i used a variac to change the voltage this time for 220V the third byte value becomes 85 and for 210V its 81 and for 100V it was 39 and so on.

I don't know how to relate 89 with 230V and also about other bytes. Plz help to decode the above output.


Solution

  • Do some ratio calculation:

    (consider the max value of a byte is 255)
    255 / 89 * 230 = 658.99 (approximately 660V)
    
    85 / 255 * 660 = 220(220V)
    81 / 255 * 660 = 209.65(210V)
    39 / 255 * 660 = 100.94(100V)
    

    But you had better find the device manual to get reference.