SPISlave
SPISlave 类层次结构
使用 SPISlave 类与 SPI 主设备通信。
默认格式设置为 8 位,模式 0 和 1 MHz 的时钟频率。同步级别:不受保护。
SPISlave 类参考
公共成员函数 | |
SPISlave (PinName mosi, PinName miso, PinName sclk, PinName ssel) | |
void | format (int bits, int mode=0) |
void | frequency (int hz=1000000) |
int | receive (void) |
int | read (void) |
void | reply (int value) |
受保护的属性 | |
spi_t | _spi |
int | _bits |
int | _mode |
int | _hz |
SPISlave 示例
回复 SPI 主站作为 slave:
#include "mbed.h"
SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
int main() {
device.reply(0x00); // Prime SPI with first reply
while(1) {
if(device.receive()) {
int v = device.read(); // Read byte from master
v = (v + 1) % 0x100; // Add one to it, modulo 256
device.reply(v); // Make this the next reply
}
}
}