0

Iam trying to read voltage values from Atmel Energy meter (AtM90E32AS) IC through Raspberry pi(3b) SPI communication. I made the connection accordingly and set the register values as given in the data sheet. when i try to read the voltage value iam getting only zeros. Help me to find out the error. I attached my connection details and test code. I attached the link of Atmel Energy Meter IC datasheet also (http://ww1.microchip.com/downloads/en/devicedoc/Atmel-46003-SE-M90E32AS-Datasheet.pdf)

                Raspberry Pi Signal                Energy Meter Signal
                        GND                               GND
                        3.3V                              VCC
                        CE0                               CS(active low)
                        SCK                               SCLK
                        MOSI                              SDI
                        MISO                              SDO

Test Code:

import spidev
import time
spi = spidev.SpiDev()
spi.open(0,0)
# Settings
spi.max_speed_hz = 500000
spi.mode = 0b01

def write_EM(input):
    msb = input >> 8
    lsb = input & 0xff
    spi.xfer([msb,lsb])
    
def acc_write():
    write_EM(0x007F) # address
    #time.sleep(0.5)
    write_EM(0x55AA)
    time.sleep(0.5)

def MMODE0_write():
    write_EM(0x0033)
    #time.sleep(0.5)
    write_EM(0x0087)
    time.sleep(0.5)
    
def en_write():
    write_EM(0x0000)
    #time.sleep(0.5)
    write_EM(0x0001)
    time.sleep(0.5)
    
def PL_H_write():
    write_EM(0x0031)
    #time.sleep(0.5)
    write_EM(0x0861)
    time.sleep(0.5)

def PL_L_write():
    write_EM(0x0032)
    #time.sleep(0.5)
    write_EM(0xC468)
    time.sleep(0.5)
    
def PStartTH_write():
    write_EM(0x0035)
    #time.sleep(0.5)
    write_EM(0x0AFC)
    time.sleep(0.5)
    
def QStartTH_write():
    write_EM(0x0036)
    #time.sleep(0.5)
    write_EM(0x0AEC)
    time.sleep(0.5)
    
def PPhaseTH_write():
    write_EM(0x0038)
    #time.sleep(0.5)
    write_EM(0x00BC)
    time.sleep(0.5)
    
def Pagain_write():
    write_EM(0x0047)
    #time.sleep(0.5)
    write_EM(0x0008)
    time.sleep(0.5)
    
def Pbgain_write():
    write_EM(0x0049)
    #time.sleep(0.5)
    write_EM(0x0008)
    time.sleep(0.5)
    
def Pcgain_write():
    write_EM(0x004B)
    #time.sleep(0.5)
    write_EM(0x0008)
    time.sleep(0.5)
    
def Vr_read():
    write_EM(0x80D9)
    #time.sleep(0.5)
    readVals = spi.xfer3([0x00,0x00],2) # full duplex communication
    print("Vr:",readVals)
    time.sleep(0.5)   

x = 1
while x < 2:
    acc_write()
    MMODE0_write()
    en_write()
    PL_H_write()
    PL_L_write()
    PStartTH_write()
    QStartTH_write()
    PPhaseTH_write()
    Pagain_write()
    Pbgain_write()
    Pcgain_write()
    x += 1

while True:
    Vr_read()
    
            

The output comes like below

Vr: (0,0)
Vr: (0,1)
Vr: (0,0)
.....
            
3
  • Perhaps add a photo showing connections. How have you confirmed that you can talk to the chip?
    – joan
    Sep 7 at 9:14
  • @ Joan as you mentioned the connection was given in the reverse order. Now i corrected the mistake. but now i getting full value in the output like Vr: (255 , 255)
    – V_J viji
    Sep 7 at 10:51
  • Personally I would try SPI mode 0.
    – joan
    Sep 7 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.