以下是一个简单的 Linux 下 GPIO 模拟 SPI 驱动代码,实现了 CS 高有效、Mode3 模式、低位先发、一次发送八个 bit 的功能。
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#define CS_PIN 7 // Chip Select (CS) pin
#define SCK_PIN 11 // Serial Clock (SCK) pin
#define MOSI_PIN 9 // Master Out Slave In (MOSI) pin
#define MISO_PIN