Reputation: 1
i have a question about windows 10 iot and the SPI communication. I try to communicate with an extension board for the Raspberry PI. To communicate with the board i use SPI0. The 1st slave is on GPIO 7 (Pin 26), the 2nd Chip Select is on GPIO 24 (Pin 18) and the 3rd is on GPIO 08 (Pin 24).
The Position from the Pins is fixed by the manufacturer, the system is originally for linux.
The communication with slave 1 (CS1) works very well. But that's all. My problem is to speak with the 2nd and 3rd Slave. I tryed to use the GPIO 24 as an Input/Output GPIO to set up the communication before Read from CS0 as an dummy but no chance.
At the moment, I am using a hardware hack. I am connecting PIN 18 to PIN 24 with a cable, however, I don't want to open each system to place a cable bridge.
Is there a possibility to setup an customized windows 10 iot image for the raspberry pi to use the Pin 26 as CS0, Pin 24 as CS1 and Pin 18 as CS2 ?
Upvotes: 0
Views: 1325
Reputation: 317
You just have to indicate the device to which you are calling.
First, set the configuration of the SPI for example, using chip select line 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);
You can not use this pin in further actions! So now you should configure the output ports using GpioPin class, which you will use to indicate the device.
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);
Always before transfer indicate device: (example method)
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;
}
Upvotes: 0
Reputation: 2030
As @Rita Han points out, the on-board SPI controller does not support pin 18 multiplexing for SPI chip select. However, I think it's still quite possible using the Pin 18 as the CS pin if you hack the spi driver a little bit.
So the inbox SPI driver is located in here, https://github.com/ms-iot/bsp/tree/master/drivers/spi/bcm2836, if you look at the source code, you can see before and after every SPI data transfer, it's setting up the SPI register to toggle the chip select pin.
So what you can do in here is instead of using the default on-board spi driver, try using the GPIO controller to toggle the pin 18 voltage, in the inbox SPI driver.
The SPI chip select pin has slack timing requirement, so i think it should be OK to use the GPIO timing.
After which, you'll need to follow some tutorial to create custom windows iot image.
Upvotes: 1