ADE7758 Arduino communication issues.

Hello guys!

I have a project using Arduino Uno and ADE7758, but I can't communicate with ADE7758 since now.

Below is my sketch.

#include <SPI.h>

#define slaveSelectPin 10
#define SPIfreq 125000

void setup()
{
  Serial.begin(115200);
  SPI.begin();
  pinMode(slaveSelectPin, OUTPUT);
  digitalWrite(slaveSelectPin, HIGH);
  delay(1000);
}

void loop()
{ 
  double opmode = adeRead(0x15, 1);
  Serial.println(opmode);
  double mmode = adeRead(0x14, 1);
  Serial.println(mmode);
  double compmode = adeRead(0x16, 1);
  Serial.println(compmode);
  double lcycmode = adeRead(0x17, 1);
  Serial.println(lcycmode);
  delay(1000);  
}

double adeRead(int address, int bytes) {
  uint32_t aux1 = 0;
  uint32_t aux2 = 0;
  uint32_t aux3 = 0;
  SPI.beginTransaction(SPISettings(SPIfreq, MSBFIRST, SPI_MODE0));
  digitalWrite(slaveSelectPin, LOW);
  SPI.transfer(address);
  delayMicroseconds(20);
  switch (bytes) {
    case 3:
      aux1 = SPI.transfer(0x00);
      bytes--;
    case 2:
      aux2 = SPI.transfer(0x00);
      bytes--;
    case 1:
      aux3 = SPI.transfer(0x00);
      break;
    default:
      break;
  }
  digitalWrite(slaveSelectPin, HIGH);
  SPI.endTransaction();
  return aux1 << 16 | aux2 << 8 | aux3;
}

Here is my schematic.

And below the SPI signals captured by a logic analyzer.

In the example above, is the first instructions of the code (a read operation in OPMODE register). As you see, the ADE7758 always return 255, no matter the operation or register accessed. 

I also compared the times from logic analyzer with the datasheet.

Time  Datasheet    Measured
t1       50ns (min)   10.5µs
t2       50ns (min)    4.125µs
t3       50ns (min)    4µs
t4       10ns (min)    4µs
t5       5ns (min)      4µs
t6       1.2µs (min)   83µs
t7       400ns (min)  23.25µs
t8       100ns (min)  4µs
t9       4µs (min)      23.25µs
t10     50ns (min)    23.25µs
t11     30ns (min)    4µs

Can you see a problem with this project? Is something that I am doing wrong?

Thank you in advance.

Parents Reply Children