Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

jackoneil

Member Since 04 Apr 2011
Offline Last Active Dec 01 2011 07:51 AM
-----

Topics I've Started

another SPI-problem

05 July 2011 - 09:29 AM

Hi community,

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.

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.