2016-02-26 70 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; 
} 
相关问题