Advertisement
Guest User

Untitled

a guest
Jul 6th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.Net.Sockets;
  4. using System.Threading;
  5. using Microsoft.SPOT;
  6. using Microsoft.SPOT.Hardware;
  7. using SecretLabs.NETMF.Hardware;
  8. using SecretLabs.NETMF.Hardware.NetduinoPlus;
  9. using System.IO.Ports;
  10.  
  11. namespace SPITest
  12. {
  13.     public class Program
  14.     {
  15.         private static SPI SPIBus;
  16.  
  17.         public static void Main()
  18.         {
  19.             // Defines the first SPI slave device with pin 10 as SS
  20.             SPI.Configuration Device1 = new SPI.Configuration(
  21.                 Pins.GPIO_NONE,         // SS-pin
  22.                 false,                  // SS-pin active state
  23.                 0,                     // The setup time for the SS port
  24.                 0,                     // The hold time for the SS port
  25.                 false,                  // The idle state of the clock
  26.                 false,                   // The sampling clock edge (this must be "true" for the 74HC595)
  27.                 250,                     // The SPI clock rate in KHz
  28.                 SPI.SPI_module.SPI1     // The used SPI bus (refers to a MOSI MISO and SCLK pinset)
  29.             );
  30.             // Initializes the SPI bus, with the first slave selected
  31.             SPIBus = new SPI(Device1);
  32.  
  33.             //DoWorkSlow();
  34.             DoWorkFast();
  35.         }
  36.  
  37.         private static void DoWorkFast()
  38.         {
  39.             //set-up the desired buffer
  40.             byte[] bufferHighBit = new byte[] { 0xFF, 0xF0, 0x00 };
  41.             byte[] bufferLowBit = new byte[] { 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00 };
  42.            
  43.             while (true)
  44.             {
  45.                 //SPIBus.Write(bufferLowBit);
  46.                 SPIBus.Write(bufferHighBit);
  47.             }
  48.  
  49.         }
  50.         private static void DoWorkSlow()
  51.         {
  52.             //set-up a one-byte buffer
  53.             byte[] buffer = new byte[1];
  54.  
  55.             while (true)
  56.             {
  57.                 for (int i = 0; i < 8; i++)
  58.                 {
  59.                     buffer[0] = (byte)i;
  60.                     SPIBus.Write(buffer);
  61.                 }
  62.  
  63.                 Thread.Sleep(5);
  64.             }
  65.         }
  66.  
  67.  
  68.  
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement