예제 #1
0
        /// <summary>
        /// Starts the Treehopper's SPI interface.
        /// </summary>
        /// <param name="Mode">Configures clock polarity and phase</param>
        /// <param name="RateMHz"></param>
        /// <param name="ChipSelect"></param>
        /// <param name="ChipSelectPolarity"></param>
        /// <param name="ChipSelectDelayMilliseconds"></param>
        /// <param name="InputMode">Chooses whether incoming data is sampled in the middle of the valid data period, or at the end. Most modern sensors produce valid output data in the middle of the waveform period.</param>
        public void Start(SPIMode Mode, double RateMHz, Pin ChipSelect = null, PinPolarity ChipSelectPolarity = PinPolarity.ActiveLow, int ChipSelectDelayMilliseconds = 0, SPISampleMode InputMode = SPISampleMode.Middle)
        {
            this.ChipSelect = ChipSelect;
            this.ChipSelectPolarity = ChipSelectPolarity;
            if(this.ChipSelect != null)
            {
                this.ChipSelect.MakeDigitalOutput();
                if (ChipSelectPolarity == PinPolarity.ActiveLow)
                    this.ChipSelect.DigitalValue = true;
                else
                    this.ChipSelect.DigitalValue = false;
            }

            double SSPADD = (120.0 / RateMHz - 1);
            if (SSPADD > 255)
            {
                throw new Exception("SPI Rate out of limits. Valid rate is 46.875 kHz - 12 MHz");
            }
            byte[] dataToSend = new byte[4];
            dataToSend[0] = (byte)DeviceCommands.SPIConfig;
            dataToSend[1] = (byte)Mode;
            dataToSend[2] = (byte)InputMode;
            dataToSend[3] = (byte)SSPADD;
            device.sendCommsConfigPacket(dataToSend);
        }
예제 #2
0
        /// <summary>
        /// Starts the Treehopper's SPI interface.
        /// </summary>
        /// <param name="Mode">Configures clock polarity and phase</param>
        /// <param name="RateMHz"></param>
        /// <param name="ChipSelect"></param>
        /// <param name="ChipSelectPolarity"></param>
        /// <param name="ChipSelectDelayMilliseconds"></param>
        /// <param name="InputMode">Chooses whether incoming data is sampled in the middle of the valid data period, or at the end. Most modern sensors produce valid output data in the middle of the waveform period.</param>
        public void Start(SPIMode Mode, double RateMHz, Pin ChipSelect = null, PinPolarity ChipSelectPolarity = PinPolarity.ActiveLow, int ChipSelectDelayMilliseconds = 0, SPISampleMode InputMode = SPISampleMode.Middle)
        {
            this.ChipSelect         = ChipSelect;
            this.ChipSelectPolarity = ChipSelectPolarity;
            if (this.ChipSelect != null)
            {
                this.ChipSelect.MakeDigitalOutput();
                if (ChipSelectPolarity == PinPolarity.ActiveLow)
                {
                    this.ChipSelect.DigitalValue = true;
                }
                else
                {
                    this.ChipSelect.DigitalValue = false;
                }
            }

            double SSPADD = (120.0 / RateMHz - 1);

            if (SSPADD > 255)
            {
                throw new Exception("SPI Rate out of limits. Valid rate is 46.875 kHz - 12 MHz");
            }
            byte[] dataToSend = new byte[4];
            dataToSend[0] = (byte)DeviceCommands.SPIConfig;
            dataToSend[1] = (byte)Mode;
            dataToSend[2] = (byte)InputMode;
            dataToSend[3] = (byte)SSPADD;
            device.sendCommsConfigPacket(dataToSend);
        }