2016-02-26 69 views
0

我已成功地與單個SPI設備(MCP3008)進行通信。是否有可能在Windows 10 iot上運行多個(4x)SPI樹莓派pi 2設備?在rasberry pi 2上運行windows 10的多個(4x)SPI設備iot

  1. 我想手動連接的CS(片選)線和調用SPI功能及活性完成它的SPI功能之後才激活它。 它可以在Windows 10 IOT上工作嗎?
  2. 配置spi片選引腳如何?在SPI初始化期間更改引腳號?那可能嗎?
  3. 在windows 10 iot上使用多個(4 x MCP3008)SPI設備的更智能的方法?

(我打算監控32個模擬信號,將被輸入到我的樹莓派2運行的是Windows 10 IOT)

非常感謝!

回答

0

來自:https://projects.drogon.net/understanding-spi-on-the-raspberry-pi/

樹莓裨只有在這個時候實現主模式,並具有2芯片選擇引腳,所以可以控制2個SPI設備。 (雖然有些設備有自己的子尋址方案,所以你可以把更多的人在同一總線上)

我已經成功地使用內賈裏德Bienz安的IoT Devices GitHub repoDeviceTester projectBreathalyzer project 2個SPI設備。

請注意,在每個項目中,SPI接口描述符都是在這兩個項目中使用的ADC和Display的ControllerName屬性中明確聲明的。有關呼吸試驗項目的詳細信息可以在我的blog上找到。

// ADC 
    // Create the manager 
    adcManager = new AdcProviderManager(); 

    adcManager.Providers.Add(
     new MCP3208() 
     { 
      ChipSelectLine = 0, 
      ControllerName = "SPI1", 
     }); 

    // Get the well-known controller collection back 
    adcControllers = await adcManager.GetControllersAsync(); 

    // Create the display 
    var disp = new ST7735() 
    { 
     ChipSelectLine = 0, 
     ClockFrequency = 40000000, // Attempt to run at 40 MHz 
     ControllerName = "SPI0", 
     DataCommandPin = gpioController.OpenPin(12), 
     DisplayType = ST7735DisplayType.RRed, 
     ResetPin = gpioController.OpenPin(16), 

     Orientation = DisplayOrientations.Portrait, 
     Width = 128, 
     Height = 160, 
    }; 
0

當然,您可以使用盡可能多的(儘可能多的GPIO引腳)。 您只需指明您要撥打的設備即可。

首先,設置SPI的配置,例如,使用片選線0

settings = new SpiConnectionSettings(0); //chip select line 0 
settings.ClockFrequency = 1000000; 
settings.Mode = SpiMode.Mode0; 

String spiDeviceSelector = SpiDevice.GetDeviceSelector(); 
devices = await DeviceInformation.FindAllAsync(spiDeviceSelector); 
_spi1 = await SpiDevice.FromIdAsync(devices[0].Id, settings); 

不能在採取進一步行動使該引腳!所以現在您應該使用GpioPin類來配置輸出端口,您將使用它來指示設備。

GpioPin_19 = IoController.OpenPin(19); 
GpioPin_19.Write(GpioPinValue.High); 
GpioPin_19.SetDriveMode(GpioPinDriveMode.Output); 

GpioPin_26 = IoController.OpenPin(26); 
GpioPin_26.Write(GpioPinValue.High); 
GpioPin_26.SetDriveMode(GpioPinDriveMode.Output); 

GpioPin_13 = IoController.OpenPin(13); 
GpioPin_13.Write(GpioPinValue.High); 
GpioPin_13.SetDriveMode(GpioPinDriveMode.Output); 

始終之前轉移指示裝置:(示例方法)

private byte[] TransferSpi(byte[] writeBuffer, byte ChipNo) 
{ 
    var readBuffer = new byte[writeBuffer.Length]; 

    if (ChipNo == 1) GpioPin_19.Write(GpioPinValue.Low); 
    if (ChipNo == 2) GpioPin_26.Write(GpioPinValue.Low); 
    if (ChipNo == 3) GpioPin_13.Write(GpioPinValue.Low); 

    _spi1.TransferFullDuplex(writeBuffer, readBuffer); 

    if (ChipNo == 1) GpioPin_19.Write(GpioPinValue.High); 
    if (ChipNo == 2) GpioPin_26.Write(GpioPinValue.High); 
    if (ChipNo == 3) GpioPin_13.Write(GpioPinValue.High); 

    return readBuffer; 
} 
相關問題