Beispiel #1
0
        private ushort ReadRegister(byte reg)
        {
            uint cmd = 0x80000000 | (((uint)reg) << 17);

            if (!CalcParity(cmd))
            {
                cmd |= 1u;
            }

            // big endian   102
            byte[] buf = new byte[]
            {
                (byte)((cmd >> 24) & 0xff),
                (byte)((cmd >> 16) & 0xff),
                (byte)((cmd >> 8) & 0xff),
                (byte)(cmd & 0xff)
            };

            m_spi.Write(buf, 4);
            m_spi.Read(false, buf, 4);

            if ((buf[0] & 0xe0) == 0)
            {
                return(0);                       // error, return 0
            }
            return((ushort)((BytesToIntBE(buf) >> 5) & 0xffff));
        }