我已经成功地通信了单个SPI设备(MCP3008)。这是否可能在带有windows 10物联网的raspberry pi 2上运行多个(4x) SPI设备?
(我计划监控32个模拟信号,这些信号将输入我运行windows 10物联网的raspberry pi 2)。
非常感谢!
发布于 2017-02-28 00:05:22
当然,你可以使用你想要的多少(多少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;
}发布于 2016-02-26 18:38:19
来自:https://projects.drogon.net/understanding-spi-on-the-raspberry-pi/
Raspberry Pi此时只实现主模式,并有2个芯片选择引脚,因此可以控制2个SPI设备。(虽然有些设备有自己的子寻址方案,所以您可以将更多的子寻址方案放在同一总线上)
我已经成功地在DeviceTester项目和透气器工程中使用了Jared的IoT器件GitHub回购中的两个SPI设备。
请注意,在每个项目中,SPI接口描述符都显式地在ADC的ControllerName属性中声明,并显示在这两个项目中。有关Breathalyzer项目的详细信息可以在我的博客上找到。
// 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,
};https://stackoverflow.com/questions/35647533
复制相似问题