Paradigm
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
Can any expert here help me with my problem. Thanks a lot for your help
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);
SPI.transfer(0x08); //Read register 4
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