2016-09-23 20:52:09 +00:00
|
|
|
/* unit test for PortMCP23S17
|
|
|
|
Picture of hardware is in unit_tests/PortMCP23S17_read/PortMCP23S17_bb.JPG
|
2016-09-01 02:29:59 +00:00
|
|
|
The setup is an MCP23S17 I/O expander on a Teensy LC controller.
|
|
|
|
MCP23S17 port-B pins are alternately grounded and energized.
|
|
|
|
portBState is a bitwise reading of port B.
|
|
|
|
output is: 10101010
|
|
|
|
*/
|
2016-09-11 15:54:10 +00:00
|
|
|
|
2016-09-01 02:29:59 +00:00
|
|
|
#include "PortIOE.h"
|
2016-09-23 20:52:09 +00:00
|
|
|
#include "PortMCP23S17.h"
|
2016-09-01 02:29:59 +00:00
|
|
|
|
2016-09-03 20:25:22 +00:00
|
|
|
const uint8_t PortIOE::DEVICE_ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded
|
2016-09-23 20:52:09 +00:00
|
|
|
PortIOE portB(1);
|
2016-09-01 02:29:59 +00:00
|
|
|
|
2016-09-23 20:52:09 +00:00
|
|
|
PortMCP23S17 portBRead(portB, ~0);
|
2016-09-01 02:29:59 +00:00
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
2016-09-17 21:47:37 +00:00
|
|
|
uint8_t portBState; //bit pattern
|
2016-09-01 02:29:59 +00:00
|
|
|
|
|
|
|
delay(6000);
|
2016-09-23 20:52:09 +00:00
|
|
|
portBRead.begin(HIGH); //HIGH or LOW, not matter
|
2016-09-01 02:29:59 +00:00
|
|
|
|
|
|
|
portBState = portBRead.read();
|
|
|
|
Keyboard.print("portBState = ");
|
2016-09-01 07:08:52 +00:00
|
|
|
Keyboard.println(portBState, BIN); //prints 10101010
|
2016-09-01 02:29:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() { }
|