当前位置: 首页>>代码示例>>C#>>正文


C# SPI.WriteRead方法代码示例

本文整理汇总了C#中Microsoft.SPOT.Hardware.SPI.WriteRead方法的典型用法代码示例。如果您正苦于以下问题:C# SPI.WriteRead方法的具体用法?C# SPI.WriteRead怎么用?C# SPI.WriteRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.SPOT.Hardware.SPI的用法示例。


在下文中一共展示了SPI.WriteRead方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestSPI

        void TestSPI()
        {
            SPI spi = new SPI(new SPI.Configuration((Cpu.Pin)28, false, 0, 0, false, false, 1, SPI.SPI_module.SPI1));
            byte[] write = new byte[] { 0, 0, 0 };
            byte[] read = new byte[] { 0, 0, 0 };

            spi.WriteRead(write, read, 2);
            spi.WriteRead(write, read, 2);
        }
开发者ID:prabby,项目名称:miniclr,代码行数:9,代码来源:ProgramSend.cs

示例2: Main

 public static void Main()
 {
     
     SerialPort UART = new SerialPort("COM1", 9600);
     SPI.Configuration config = new SPI.Configuration((Cpu.Pin)FEZ_Pin.Digital.Di10, false, 0, 0, true, true, 250, SPI.SPI_module.SPI1);
     SPI Spi = new SPI(config);
     UART.Open();
     string Datoreaded = "";
     byte[] datain = new byte[1];
     byte[] dataout = new byte[1];
     while (true)
     {
         // Sleep for 500 milliseconds
         Thread.Sleep(500);
         
         dataout[0] = (byte)0x55;
         datain[0] = (byte)0;
         Spi.WriteRead(dataout, datain);
         Datoreaded = datain[0].ToString();
         Datoreaded += "\n\r";
         byte[] buffer = Encoding.UTF8.GetBytes(Datoreaded);
         UART.Write(buffer, 0, buffer.Length);
         
     }
 }
开发者ID:sarathjeeva,项目名称:mfrclib4arm,代码行数:25,代码来源:Program.cs

示例3: Main

        public static void Main()
        {
            SPI.Configuration[] max6675SpiCfg;
            // variables that will be used to extract the information from
            // the incoming serial bits from the MAX6675 chip
            byte[] outBfr = new byte[2];
            byte[] inBfr = new byte[2];

            // data will be used to store the extracted information
            short data;
            double tempF;
            double tempC;
            double tempK;
            int count = 0;

            max6675SpiCfg = new SPI.Configuration[1];

            max6675SpiCfg[0] = new SPI.Configuration(
                Pins.GPIO_PIN_D8,       //  CS to digtalOut pin 9
                false,                  //  CS pin active state
                0,                      //  CS port set up time
                0,                      //  CS port hold time
                false,                  //  Idle state of clock
                true,                   //  Signal edge to sample on
                1000,                   //  Clock speed in KHz
                SPI_Devices.SPI1        //  Using SPI bus 1
                );

            // Creating a new instance of SPI object
            max6675Spi = new SPI (max6675SpiCfg[0]);

            //Reading from MAX6675 board and displaying data
            while(true)
            {
                max6675Spi.Config = max6675SpiCfg[0];
                max6675Spi.WriteRead(outBfr, inBfr);

                data = (short) (inBfr[0] << 5 | inBfr[1] >> 3);

                tempC = data / 4.0;
                tempK = tempC + 273.15;
                tempF = tempC * 1.8 + 32.0;

                // using debug to output the information to the computer screen
                Debug.Print(" Reading:" + count.ToString("F"));
                Debug.Print(" Temp F:" + tempF.ToString("F"));
                Debug.Print(" Temp C:" + tempC.ToString("F"));
                Debug.Print(" ");

                Thread.Sleep(500);

                count++;
            }
        }
开发者ID:bdk1417,项目名称:NetduinoThermocouple,代码行数:54,代码来源:Program.cs

示例4: ReadReg

 public static int ReadReg(SPI spi, byte Addr)
 {
     int RetVal;
     var TxBuffer = new byte[6];
     var RxBuffer = new byte[6];
     TxBuffer[0] = 0x00;
     TxBuffer[1] = Addr;
     TxBuffer[2] = 0x00;
     TxBuffer[3] = 0x00;
     TxBuffer[4] = 0x00;
     TxBuffer[5] = 0x00;
     spi.WriteRead(TxBuffer, RxBuffer);
     RetVal = (int)((RxBuffer[2] << 24) + (RxBuffer[3] << 16) + (RxBuffer[4] << 8) + (RxBuffer[5]));
     return RetVal;
 }
开发者ID:wramsdell,项目名称:Netduino_Example,代码行数:15,代码来源:Program.cs

示例5: GetVersion

 public static uint GetVersion(SPI spi)
 {
     uint RetVal;
     var TxBuffer = new byte[6];
     var RxBuffer = new byte[6];
     TxBuffer[0] = 0xFF;
     TxBuffer[1] = 0x00;
     TxBuffer[2] = 0x00;
     TxBuffer[3] = 0x00;
     TxBuffer[4] = 0x00;
     TxBuffer[5] = 0x00;
     spi.WriteRead(TxBuffer, RxBuffer);
     RetVal = (uint)((RxBuffer[2] << 24) + (RxBuffer[3] << 16) + (RxBuffer[4] << 8) + (RxBuffer[5]));
     return RetVal;
 }
开发者ID:wramsdell,项目名称:Netduino_Example,代码行数:15,代码来源:Program.cs

示例6: GetMemory

 public static uint GetMemory(SPI spi, byte address)
 {
     uint RetVal;
     var TxBuffer = new byte[6];
     var RxBuffer = new byte[6];
     TxBuffer[0] = 0x00;
     TxBuffer[1] = address;
     TxBuffer[2] = 0x00;
     TxBuffer[3] = 0x00;
     TxBuffer[4] = 0x00;
     TxBuffer[5] = 0x00;
     spi.WriteRead(TxBuffer, RxBuffer);
     RetVal = (uint)((RxBuffer[2] << 24) + (RxBuffer[3] << 16) + (RxBuffer[4] << 8) + (RxBuffer[5]));
     return RetVal;
 }
开发者ID:wramsdell,项目名称:Netduino_Example,代码行数:15,代码来源:Program.cs

示例7: Main

        public static void Main()
        {
            byte[] TxBuff = new byte[4]{0x9F,0xA5,0xA5,0xA5};
            byte[] RxBuff = new byte[4];

            SPI.Configuration SPI_Config = new SPI.Configuration(Pins.GPIO_PIN_D10, false, 0, 1, false, true, 1000,SPI.SPI_module.SPI1);
            //the 6th parameter, clock edge ,only care whether MOSI data is latched on the SPI Clock rising edge(true) or falling edge(falling),not the MISO.

            SPI SPI1 = new SPI(SPI_Config);

            while (true)
            {
                SPI1.WriteRead(TxBuff, RxBuff);

                Debug.Print("Manufacture ID:"+RxBuff[1].ToString("X"));
                Debug.Print("Device ID High byte:"+RxBuff[2].ToString("X"));
                Debug.Print("Device ID Low byte:"+RxBuff[3].ToString("X"));

                Thread.Sleep(500);
            }

            // write your code here
        }
开发者ID:rmerouze,项目名称:Netduino,代码行数:23,代码来源:Program.cs

示例8: RedLEDOn

 public static void RedLEDOn(SPI spi)
 {
     byte[] TxBuffer = { 0x04, 0x01 };
     byte[] RxBuffer = new byte[2];
     spi.WriteRead(TxBuffer, RxBuffer);
 }
开发者ID:wramsdell,项目名称:Netduino_Example,代码行数:6,代码来源:Program.cs

示例9: PWMStop

 public static void PWMStop(SPI spi)
 {
     byte[] TxBuffer = { 0x02, 0x00 };
     byte[] RxBuffer = new byte[2];
     spi.WriteRead(TxBuffer, RxBuffer);
 }
开发者ID:wramsdell,项目名称:Netduino_Example,代码行数:6,代码来源:Program.cs

示例10: GreenLEDOff

 public static void GreenLEDOff(SPI spi)
 {
     byte[] TxBuffer = { 0x03, 0x00 };
     byte[] RxBuffer = new byte[2];
     spi.WriteRead(TxBuffer, RxBuffer);
 }
开发者ID:wramsdell,项目名称:Netduino_Example,代码行数:6,代码来源:Program.cs

示例11: WriteReg

 public static void WriteReg(SPI spi, byte Addr, int Data)
 {
     var TxBuffer = new byte[6];
     var RxBuffer = new byte[6];
     TxBuffer[0] = 0x01;
     TxBuffer[1] = Addr;
     TxBuffer[2] = (byte)(Data >> 24 & 0xFF);
     TxBuffer[3] = (byte)(Data >> 16 & 0xFF);
     TxBuffer[4] = (byte)(Data >> 8 & 0xFF);
     TxBuffer[5] = (byte)(Data & 0xFF);
     spi.WriteRead(TxBuffer, RxBuffer);
 }
开发者ID:wramsdell,项目名称:Netduino_Example,代码行数:12,代码来源:Program.cs

示例12: SetTerminate

 public static void SetTerminate(SPI spi, int Data)
 {
     var TxBuffer = new byte[6];
     var RxBuffer = new byte[6];
     TxBuffer[0] = 0x05;
     TxBuffer[1] = 0x00;
     TxBuffer[2] = (byte)(Data >> 24 & 0xFF);
     TxBuffer[3] = (byte)(Data >> 16 & 0xFF);
     TxBuffer[4] = (byte)(Data >> 8 & 0xFF);
     TxBuffer[5] = (byte)(Data & 0xFF);
     spi.WriteRead(TxBuffer, RxBuffer);
 }
开发者ID:wramsdell,项目名称:Netduino_Example,代码行数:12,代码来源:Program.cs

示例13: calculatePressure

        /// <summary>
        /// 
        /// SPI interface for the MPL115A barometric sensor.
        /// Created by deepnarc, deepnarc at gmail.com
        /// 
        /// Netduino platform
        /// 
        /// Sensor Breakout---------Netduino
        /// ================================
        /// SDN---------------------optional
        /// CSN---------------------pin 0 (user definable)
        /// SDO---------------------pin 12
        /// SDI---------------------pin 11
        /// SCK---------------------pin 13
        /// GND---------------------GND
        /// VDO---------------------VCC (3.3V)
        /// 
        /// References: (1) Freescale Semiconductor, Application Note, AN3785, Rev 5, 7/2009 by John Young
        /// provided the code for the manipulations of the sensor coefficients; the original comments 
        /// were left in place without modification in that section. (2) Freescale Semiconductor, Document 
        /// Number: MPL115A1, Rev 6, 10/2011. (3) MPL115A1 SPI Digital Barometer Test Code Created on: 
        /// September 30, 2010 By: Jeremiah McConnell - miah at miah.com, Portions: Jim Lindblom - jim at 
        /// sparkfun.com. (4) MPL115A1 SPI Digital Barometer Test Code Created on: April 20, 2010 By: Jim 
        /// Lindblom - jim at sparkfun.com.
        /// 
        /// </summary>
        public static double calculatePressure()
        {
            SPI SPI_Out = new SPI(new SPI.Configuration(
                (Cpu.Pin)FEZ_Pin.Digital.Di7,    // SS-pin
                false,               // SS-pin active state
                0,                   // The setup time for the SS port
                0,                   // The hold time for the SS port
                false,               // The idle state of the clock
                true,                // The sampling clock edge
                1000,                // The SPI clock rate in KHz
                SPI.SPI_module.SPI1  // The used SPI bus (refers to a MOSI MISO and SCLK pinset)
                )
            );

            string decPcomp_out;
            sbyte sia0MSB, sia0LSB;
            sbyte sib1MSB, sib1LSB;
            sbyte sib2MSB, sib2LSB;
            sbyte sic12MSB, sic12LSB;
            sbyte sic11MSB, sic11LSB;
            sbyte sic22MSB, sic22LSB;
            int sia0, sib1, sib2, sic12, sic11, sic22;
            uint uiPadc, uiTadc;
            byte uiPH, uiPL, uiTH, uiTL;
            long lt1, lt2, lt3, si_c11x1, si_a11, si_c12x2;
            long si_a1, si_c22x2, si_a2, si_a1x1, si_y1, si_a2x2;
            float siPcomp;//, decPcomp;

            // start pressure & temp conversions
            // command byte + r/w bit
            const byte com1_writeData = 0x24 & 0x7F;
            const byte com2_writeData = 0x00 & 0x7F;
            byte[] WriteBuffer = { com1_writeData, com2_writeData };
            SPI_Out.Write(WriteBuffer);
            Thread.Sleep(3);

            // write(0x24, 0x00);	// Start Both Conversions
            // write(0x20, 0x00);	// Start Pressure Conversion
            // write(0x22, 0x00);	// Start temperature conversion
            // delay_ms(10);	    // Typical wait time is 3ms

            // read pressure
            // address byte + r/w bit
            // data byte + r/w bit
            const byte PRESHw_writeData = 0x00 | 0x80;
            const byte PRESHr_writeData = 0x00 | 0x80;
            const byte PRESLw_writeData = 0x02 | 0x80;
            const byte PRESLr_writeData = 0x00 | 0x80;
            const byte TEMPHw_writeData = 0x04 | 0x80;
            const byte TEMPHr_writeData = 0x00 | 0x80;
            const byte TEMPLw_writeData = 0x06 | 0x80;
            const byte TEMPLr_writeData = 0x00 | 0x80;
            const byte BLANK1r_writeData = 0x00 | 0x80;

            byte[] press_writeData = { PRESHw_writeData, PRESHr_writeData, PRESLw_writeData, PRESLr_writeData,
                                       TEMPHw_writeData, TEMPHr_writeData, TEMPLw_writeData, TEMPLr_writeData, BLANK1r_writeData };
            byte[] press_readBuffer = new byte[9];

            SPI_Out.WriteRead(press_writeData, press_readBuffer);

            uiPH = press_readBuffer[1];
            uiPL = press_readBuffer[3];
            uiTH = press_readBuffer[5];
            uiTL = press_readBuffer[7];

            uiPadc = (uint)uiPH << 8;
            uiPadc += (uint)uiPL & 0x00FF;
            uiTadc = (uint)uiTH << 8;
            uiTadc += (uint)uiTL & 0x00FF;

            // read coefficients
            // address byte + r/w bit
            // data byte + r/w bit
            const byte A0MSBw_writeData = 0x08 | 0x80;
//.........这里部分代码省略.........
开发者ID:zgramana,项目名称:WeatherStation,代码行数:101,代码来源:PressureSensor.cs


注:本文中的Microsoft.SPOT.Hardware.SPI.WriteRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。