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 Measuredt1 50ns (min) 10.5µst2 50ns (min) 4.125µst3 50ns (min) 4µst4 10ns (min) 4µst5 5ns (min) 4µst6 1.2µs (min) 83µst7 400ns (min) 23.25µst8 100ns (min) 4µst9 4µs (min) 23.25µst10 50ns (min) 23.25µst11 30ns (min) 4µs
Can you see a problem with this project? Is something that I am doing wrong?
Thank you in advance.
Hi
From your scope captures I think miso and spi clk are shorted together on the ADE7758 can you please verify this with a volt meter and remove the short.
Dave
Please add decoupling to your 5v near arduino and ADE7758.
Also add decoupling to the REF pin on the ADE7758. This is and internally generated ref that needs decoupling see pg 17 for test ckt. see pin description pg 9.
You also don't need the bytes-; in your case statements.
Your data (address) is changing on the falling edge data should change on the rising edge and clocked in on the falling edge. fig 94 pg 58
Hello Dave,
Thank you for your answer.
I made the changes that you recommended.
Please see the following schematic and output from the logic analyzer.
Above is a read operation in OPMODE register (address 0x15).In the code I changed the SPI mode to 1 (CPOL=0, CPHA=1).I didn't note any changes in the MISO pin but Arduino did, before this changes the output printed in the serial was always 0, now it is printing other values:
OPMODE (0x13) = 15.00MMODE (0x14) = 253.00COMPMODE (0x16) = 63.00LCYCMODE (0x17) = 255.00
This is not the default values of these registers, and even when I try to write some values like 0x04 in OPMODE, it continues reading 15 (0xF). Is there something else I can do?
Can you use a scope so I can see the serial levels ?
Also verify crystal is running with a scope. You will get no response if crystal is not running. Can you also measure the reference voltage.
I don't have a scope with me now, I will get one in a few days and then report the results of the tests.
Thank you very much for your support.
Here is the crystal waveform.