Table of contents
Raspberry Pi Windows IoT Development (Part 1)
Raspberry Pi Windows IoT Development (Part 2) USB Camera
Raspberry Pi Windows IoT Development (Part 3) Flashing LED
Raspberry Pi Windows IoT Development (IV) UART Interface
Raspberry Pi Windows IoT Development (V) SPI Interface
The Raspberry Pi has two SPI bus interfaces, SPI0 and SPI1. I have an SD1306 SPI display screen. This screen only uses two SPI lines, SCLK and MOSI, because there is no need to communicate with the screen and therefore no MISO line. In addition to the SPI data line, the CS line (enable), RST line (reset) and CDS line (data/command) are also required. My screen is a little different from the one used by Microsoft, but the functions are compatible. The RST and CDS lines are connected to ordinary GPIO, and CS is connected to the enable line of SPI0.
Hardware: An SD1306 OLED display screen with SPI interface. 7 Dupont lines.
Raspberry Pi development board RPI3B+, HDMI, mouse, USB, power cord, etc.
Data link: ttps://github.com/Microsoft/Windows-iotcore-samples/tree/master/Samples/SPIDisplay
Connect as required
Open the SPIDisplay sample program with VS2019
No need to modify the program, just run it directly.
You can see that the program has been started.
You can see that the text is consistent with the display. Why is it a little "blurry"? This is because the screen has a reverse display, but it is not done well.
The purpose of this article is to introduce the operation of the SPI bus, so the code used is slightly different from the SPIDisplay code.
") rgba(220, 220, 220, 0.5); left: 0px; top: -15px; display: block;">
This is the code for GPIO initialization. Set RST and DCS to GPIO output mode.
") rgba(220, 220, 220, 0.5); left: 0px; top: -15px; display: block;">
There are mainly two steps
1. Define a setting object to set the connection parameters of the peripheral, such as working mode and communication rate
settings.ClockFrequency = 10000000;
settings.Mode = SpiMode.Mode3; No response
2. Select and open the device
string spiAqs = SpiDevice.GetDeviceSelector(SPI_CONTROLLER_NAME);
SpiDisplay = await SpiDevice.FromIdAsync(devicesInfo[0].Id, settings);
SpiDisplay is the defined SPI device object
After the device is ready, you can write data
") rgba(220, 220, 220, 0.5); left: 0px; top: -15px; display: block;">
DtaCommandPin.Write(GpioPinValue.High);//GPIO read and write, set command/data
SpiDisplay.Write(Data);//Write SPI data
Windows iot device operations are asynchronously operated by the driver, so users do not need to worry about multi-task synchronization. This is better than using an embedded operating system. Therefore, programs developed using the Windows iot system are simple and more stable!
This content is originally created by bigbat, a user of EEWORLD forum. If you want to reprint or use it for commercial purposes, you need to obtain the author's consent and indicate the source