已存档
1
0
该仓库已被归档。您可以查看文件和克隆它,但不能推送、创建工单或合并请求。
keybrd/src/PortRead_MCP23S17.cpp

24 行
719 B
C++

2016-09-01 02:29:59 +00:00
#include "PortRead_MCP23S17.h"
/*
PortRead_MCP23S17::begin() is not needed because port direction is already configured to input by default.
SPI bus is configured in PortWrite_MCP23S17::begin().
*/
/*
returns port value
*/
uint8_t PortRead_MCP23S17::read()
{
uint8_t portState; //bit wise
//slower clock
digitalWrite(SS, LOW); //enable Slave Select
SPI.transfer(port.ADDR << 1 | 1); //read command
SPI.transfer(port.num + 0x12); //register address to read data from
portState = SPI.transfer(0); //save the data (0 is dummy data to send)
digitalWrite(SS, HIGH); //disable Slave Select
return portState;
}