I've a problem with connecting an ADE7758 PolyPhaseMeter via SPI to my NetDuino.
My task is to build a smart meter, so getting data (Voltage and Current) from the 7758 and save it on SD-Card of my NetDuino.
My code is:
public static string Connect() { try { SPIConfig = new SPI.Configuration(Pins.GPIO_PIN_D4, // CS port false, // CS active when LOW 1, // CS Setup time in ms 1, // CS Hold time in ms false, // Clock idle is low false, // Data is sampled on falling edge of clock 10, // Clock rate in KHz SPI_Devices.SPI1); SPIConnection = new SPI(SPIConfig); Thread.Sleep(1000); Get(0x7F, 8); //for testing if something is coming back } catch (Exception ex) { return ex.ToString(); } return "ok"; }
public static string Get(byte register, ushort bit) { byte[] readBuff; if (bit <= 8) readBuff = new byte[] { 0x00 }; else if (bit <= 16) readBuff = new byte[] { 0x00, 0x00 }; else if (bit <= 24) readBuff = new byte[] { 0x00, 0x00, 0x00 }; else return "bit-Fehler"; SPIConnection.WriteRead(new byte[] { register }, readBuff); long result = 0x00; if (readBuff.Length == 1) result = readBuff[0]; else if (readBuff.Length == 2) result = (readBuff[0] << 8) + readBuff[1]; else if (readBuff.Length == 3) result = (readBuff[0] << 16) + (readBuff[1] << 8) + readBuff[2]; return result.ToString(); }
The data, I should get back from ADE, is 1 to 3 bytes with the register value of the onboard ADCs,
but geting back only 255 (or 255 255 or 255 255 255)
All cable connections are ok, I've checked twice.
In the SPIConfig I've changed every parameter, but nothing changes on the result.
Sitting here for 3 days looking for the failure.
An idea?
Thanks for help.