0

I am interfacing a M90E32AS energy meter IC with dsPIC33F series processor. I successfully read voltage and current values. I try to read power values also, as per the datasheet the power registers are 32-bits wide. I tried the following code to read the 32 bit value but I am unsuccessful. Help me to rectify the error.

int PmB_read()
{
    CS=0;
    SPI2BUF=SBUF=0x80B2;
    while(SPI2STATbits.SPITBF==1){}
    SPI2BUF=0x0;
    
    while(SPI2STATbits.SPITBF==1){}
    delay();
    
    CS=1;
    HiByte = SPI2BUF;
    return HiByte;
}

int PmBLSB_read()
{
    CS=0;
    SPI2BUF=SBUF=0x80C2;
    while(SPI2STATbits.SPITBF==1){}
    SPI2BUF=0x0;
    while(SPI2STATbits.SPITBF==1){}
    delay();
    CS=1;
    LoByte = SPI2BUF;
    TPmB = (HiByte << 16)| LoByte;
    Total = TPmB * 0.00032;
    return Total;
}

Here is the data sheet screen shot for power register

0andriy
  • 4,183
  • 1
  • 24
  • 37
V_J viji
  • 39
  • 1
  • 7
  • 1
    Does SPI master support 32-bit mode? (It really doesn't matter what the data bus width the CPU has, the problem may be on the level of SPI master or CPU integration (when bus arbiter must split longer transfers to a smaller ones to be suitable for CPU). – 0andriy Mar 07 '21 at 20:57
  • 2
    If you are spliting the transaction in parts you must keep CS active during the entire transfer. You would probably need to send six bytes to read the register. 16 bit command and then 32 pulses of dummy data to read 32 bits – Simson Mar 09 '21 at 05:09

0 Answers0