/// <summary>
        /// Sets up the SPI controller using simple enumerated types
        /// </summary>
        /// <param name="MS">Select master or slave SPI mode</param>
        /// <param name="mode">Selects clock phase and polarity based on standard SPI mode types</param>
        /// <param name="order">Data order, MSB or LSB first</param>
        /// <param name="rate">Data clock rate to be used (no effect in slave mode)</param>
        public void SPI_setup(SPI_masterSlave MS, SPI_mode mode, SPI_dataOrder order, SPI_baudRate rate)
        {
            byte SPCR = (byte)(0x40 | (byte)MS | (byte)mode | (byte)order | (byte)rate);
            byte SPSR = (byte)((byte)rate >> 2);

            SPI_setup(SPCR, SPSR);

            //if this is set as master mode, then we need an event to allow the data to be read
            SPI_replyWait = new EventWaitHandle(false, EventResetMode.AutoReset);

            if (MS == SPI_masterSlave.master)
            {
                SPI_dataReceived += new SPI_dataReceivedEvent(HU320_SPI_dataReceived);
            }
            else
            {
                SPI_dataReceived -= new SPI_dataReceivedEvent(HU320_SPI_dataReceived);
            }
        }
Пример #2
0
        /// <summary>
        /// Sets up the SPI controller using simple enumerated types
        /// </summary>
        /// <param name="MS">Select master or slave SPI mode</param>
        /// <param name="mode">Selects clock phase and polarity based on standard SPI mode types</param>
        /// <param name="order">Data order, MSB or LSB first</param>
        /// <param name="rate">Data clock rate to be used (no effect in slave mode)</param>
        public void SPI_setup(SPI_masterSlave MS, SPI_mode mode, SPI_dataOrder order, SPI_baudRate rate)
        {
            byte SPCR = (byte)(0x40 | (byte)MS | (byte)mode | (byte)order | (byte)rate);
            byte SPSR = (byte)((byte)rate >> 2);

            SPI_setup(SPCR, SPSR);

            //if this is set as master mode, then we need an event to allow the data to be read
            SPI_replyWait = new EventWaitHandle(false, EventResetMode.AutoReset);

            if (MS == SPI_masterSlave.master)
                SPI_dataReceived += new SPI_dataReceivedEvent(HU320_SPI_dataReceived);
            else
                SPI_dataReceived -= new SPI_dataReceivedEvent(HU320_SPI_dataReceived);
        }