ADE7753-Arduino Mega Interfacing Problem

Hi
I am working on a project and I am using the IC ADE7753 to measure the power consumed by the load, but the problem is that I am not able to successfully interface the IC with the Arduino Mega. The attachment contains the code and the output from the serial monitor. Any help would be great.
Thanks

ADE_ARD_Interfacing_9.ino (5.51 KB)

Output.png

After a quick look at your code and first thing that stands out is your continually doing SPI.begin & SPI.end. Just do begin in setup and remove the other begin and both ends.
Do you need time to allow chip to settle after a power on before trying to talk to it?

Thanks Riva for helping
I removed the extra begin and ends but the result is same.
Yes I think the IC need a little bit of time to settle after powering up.

Sorry for the long time between replies but am consumed with RPi coding at the moment.

Taking a slightly longer look at your code and...

The comment names of these pins is the wrong way round, though irrelevant to the code as SPI will use the correct pins but have you wired it the wrong way?

#define DATAOUT    50   //MOSI
#define DATAIN     51   //MISO

Not needed as set by SPI.begin, you only need to ensure the hardware SS pin (53) is set as output to get SPI in master mode (as input makes SPI slave mode)

  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);

I think this should be mode 1 not mode 2. CPOL = 0, CPHA = 1

  SPI.setDataMode(SPI_MODE2);     // Data are captured on the clock's falling edge and data is output on a rising edge.

Probably no need to slow the SPI down.

  SPI.setClockDivider(SPI_CLOCK_DIV8);

Something missing here?

unsigned char read8(char reg){

Would a unsigned int type be more suitable?

long read16(int adress){

Probably no need for the delays in the read/write functions.

EDIT
Some of the registers as 24 bits wide so you may also need read24 & write24 functions to go with your 8 & 16 ones.

No problem bro, really appreciate your help
I connected them as follow:

ADE7753 Arduino Mega
Pin 19(DOUT) 50
Pin 20(DIN) 51
Pin 18(SCLK) 52
Pin 17(CS) 53

I made the changes in the code as you mentioned but the results are still the same. I also attached the modified code, and yeah you are right I'll need read24 and write 24 functions as well but if I can make read8 and write8 work then I can easily modify them to get read24 and write24 functions.

ADE_ARD_Interfacing_9.ino (5.47 KB)

I have tweaked you code about just a little bit and added code so the ADE7753 is bought out of reset.

I think the pin connections should be as below...

#define DATAIN     50   // MISO Connects to ADE7753 pin 19
#define DATAOUT    51   // MOSI Connects to ADE7753 pin 20
#define SPICLOCK   52   // SCK Connects to ADE7753 pin 18
#define CS         53   // Chip Select connects to ADE7753 pin 17
#define RESET       5   // Connects to ADE7753 pin 1 (reset active low)

ADE_ARD_Interfacing_9.ino (4.93 KB)

Tried your code but the results didn't changed.
Do you have a working code for ADE7753??

I don't have proven code for the ADE7753 chip so went looking online. There seems to be a minefield of useless code fragment and misleading information.

As a last resort I have slowed down the SPI transfer speed and re-applied your delays in the SPI send/receive functions.
Just to be sure you are connecting the reset wire to the chip?
If this does not work then maybe someone else can suggest something I have missed and I will order a chip off eBay to experiment with.

ADE_ARD_Interfacing_9.ino (4.41 KB)

It didn't worked :frowning:
Anyway, Thanks a lot Riva for your help.
Just a quick question.
Can I use this IC without the voltage and current sensors at its input (V2N, V2P and V1P, V1N respectively), just to check the SPI communication?

abubakar_005:
Can I use this IC without the voltage and current sensors at its input (V2N, V2P and V1P, V1N respectively), just to check the SPI communication?

You would need to check the datasheet in detail to be sure of this but probably not a problem.
To check the SPI I would look for registers that are likely to have something in even without a sensor connected or try loading values into writeable registers and try reading them back.

You never did answer my question regarding the reset pin/wire.

Thanks a lot Riva for your time and help.
My problem is solved now and the problem was in the connections.

Riva:
You never did answer my question regarding the reset pin/wire.

I did connected the reset pin to the chip as you described but it didn't work, and in the final working code I simply connected the reset pin to supply and it worked.

abubakar_005:
I did connected the reset pin to the chip as you described but it didn't work, and in the final working code I simply connected the reset pin to supply and it worked.

The code in #5 set the reset control pin (5) as output and set it high then as you reported the chip still not working it changed the code in #7 to just turn on the internal pullup resistor on the pin.
Can you confirm neither method works.

Yes, both methods didn't worked.

abubakar_005:
Yes, both methods didn't worked.

One last idea, not sure where your powering the ADE7753 & Arduino from but have you also connected Arduino GND to ADE7753 DGND ?

Maybe I'm way off here, but it appears that device is a mode 1 device, not mode 2. Don't know if that would cause your problem.
http://www.analog.com/media/en/technical-documentation/data-sheets/ADE7753.pdf
SCLK LOW with HIGH pulses (CPOL=0) and capture on trailing edge (CPHA=1).

SurferTim:
Maybe I'm way off here, but it appears that device is a mode 1 device, not mode 2.

Mode 1 it is, see #3

Riva:
One last idea, not sure where your powering the ADE7753 & Arduino from but have you also connected Arduino GND to ADE7753 DGND ?

First of all I am really sorry for late reply as I was busy with project report and presentation etc.
Yes, I had connected Arduino GND to ADE7753 GND