# Reading values from Energy IC Chip

Status
Not open for further replies.

##### Member level 1
Dear All Expert,

I am using a Arduino Uno board to capture some data of the energy IC chip connected using SPI. Following is the link to the datasheet of the ICs https://www.cirrus.com/en/pubs/proDatasheet/CS5464_F3.pdf

I had written the program and tested on the chip but it is not showing any different when I turn on my hair dryer which is connected to the energy IC. It shows the max value of 0xFFFFFF however, the max value on the datasheet is
7FFFFF. I suspect I didnt access the IC at all or didnt even communicate with the IC. Below is my code

Code:
#include <SPI.h>

int CS=9;
byte Data, Data1, Data2;
int MSB, LSB;
long Power;

void setup() {
pinMode(CS, OUTPUT);
Serial.begin(9600);
SPI.setBitOrder(MSBFIRST);
SPI.begin();
}

void CS5464_init() {
digitalWrite(CS, LOW);
//Initalise SYNC0 and SYNC1 with CS5464
SPI.transfer(0xFF);
SPI.transfer(0xFF);
SPI.transfer(0xFF);
SPI.transfer(0xFE);
digitalWrite(CS,HIGH);
delay(10);
//Set to continous Conversion Mode
digitalWrite(CS, LOW);
SPI.transfer(0xE8);
SPI.transfer(0xFF);
SPI.transfer(0xFF);
SPI.transfer(0xFE);
digitalWrite(CS, HIGH);
delay(10);
}

void loop()
{
CS5464_init();

while(1) {
Data = Data1 = Data2 = 0;

digitalWrite(CS, LOW);
Data2 = SPI.transfer(0xFF); // SYNC1
Data1 = SPI.transfer(0xFF); // SYNC1
Data = SPI.transfer(0xFE); // SYNC0
digitalWrite(CS, HIGH);

MSB = 0x00FF & Data2;
LSB = Data1 << 8;
LSB = LSB | Data;
Power = MSB << 16;
Power = Power | LSB;

Serial.print("Power of line =");
Serial.print(Power, DEC);
Serial.println('W');
delay(1000);
}
}

Can any expert here help me with my problem. Thanks a lot for your help

#### internetuser2k12

##### Banned
Can you post the circuit you are using?

##### Member level 1
Hi Internetuser2k12,

The hardware is working properly as I got it from some vendor that do energy IC chip. I do not have the circuit diagram. But the IC breakout board do have a Vin+ and Vin-, Vout+ and Vout- to be connected to my AC supply and output of my Load. Then it have a breakout of SDO, SDI, CS and SCLK which I connect to my Arduino Uno like this (CS to pin10 SS, SDO to pin 12 MISO, SDI to pin 11 MOSI, SCLK to pin 13 SCK). Does that help? Thanks a lot for your help.

##### Member level 1

Hi Internetuser2k12,

I sort of trace the PCB breakout board for my IC and the hardware looks something like the one attached. Pls advise. Thanks alot

#### internetuser2k12

##### Banned
Your connections are right. post your code. Are you sure that you are enabling CS/SS?

##### Member level 1
Hi Internetuser2k12, my code is on the first post. I didnt change my code after that. Still cannot get my IC to work. I connect the CS to pin 9 now. I didnt use pin 10 SS anymore as i will have more IC connected together. Sorry about the confusion. But still cannot get my code working.

Status
Not open for further replies.