@@ -22,6 +22,9 @@ strobeOn is logic level of strobe on, HIGH or LOW | |||
MCP23S17 SPI interface is 10 MHz max. | |||
The electrical limitation to bus speed is bus capacitance and the length of the wires involved. | |||
Longer wires require lower clock speeds. | |||
begin() is called from Scanner_IOE::begin() twice, once each for refPortWrite and refPortRead. | |||
The first 4 lines only need to be called once, but seem to work OK if called a second time. | |||
*/ | |||
void PortMCP23S17::begin(const uint8_t strobeOn) | |||
{ | |||
@@ -41,10 +44,6 @@ void PortMCP23S17::begin(const uint8_t strobeOn) | |||
{ | |||
pullUp = 0; | |||
} | |||
//todo | |||
Keyboard.print(" strobeOn="); Keyboard.print(strobeOn); | |||
Keyboard.print(" readPins="); Keyboard.print(readPins, BIN); | |||
Keyboard.print(" pullUp="); Keyboard.println(pullUp, BIN); | |||
transfer(port.DEVICE_ADDR << 1, port.num, readPins); //configure IODIR | |||
transfer(port.DEVICE_ADDR << 1, port.num + 0x0C, pullUp); //configure GPPU | |||
@@ -65,13 +64,6 @@ void PortMCP23S17::write(const uint8_t pin, const bool logicLevel) | |||
{ | |||
port.outputVal |= pin; //set pin output to high | |||
} | |||
//todo | |||
//Keyboard.print(" readPins="); Keyboard.print(readPins, BIN); | |||
Keyboard.print(" pin="); Keyboard.print(pin, BIN); | |||
Keyboard.print(" logicLevel="); Keyboard.print(logicLevel); | |||
Keyboard.print(" outputVal="); Keyboard.println(port.outputVal, BIN); | |||
//Keyboard.print(" ="); Keyboard.print(); | |||
//delay(200); | |||
transfer(port.DEVICE_ADDR << 1, port.num + 0x12, port.outputVal); //set GPIO port to outputVal | |||
} |
@@ -13,6 +13,7 @@ Initiates communication protocal and configs ports. | |||
void Scanner_IOE::begin() | |||
{ | |||
refPortRead.begin(strobeOn); | |||
refPortWrite.begin(strobeOn); | |||
} | |||
/* scan() is called on every iteration of sketch loop(). | |||
@@ -23,13 +24,10 @@ read_pins_t Scanner_IOE::scan(const uint8_t strobePin) | |||
{ | |||
uint8_t readState; //bits, 1 means key is pressed, 0 means released | |||
delay(2000);//todo | |||
//strobe on | |||
refPortWrite.write(strobePin, strobeOn); | |||
delayMicroseconds(3); //time to stabilize voltage | |||
//delayMicroseconds(300); //todo | |||
delay(2000); | |||
//read the port pins | |||
readState = refPortRead.read(); | |||
@@ -1,5 +1,5 @@ | |||
/* unit test for PortRead_MCP23S17 | |||
Picture of hardware is in unit_tests/PortRead_MCP23S17/PortRead_MCP23S17_bb.JPG | |||
/* unit test for PortMCP23S17 | |||
Picture of hardware is in unit_tests/PortMCP23S17_read/PortMCP23S17_bb.JPG | |||
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. | |||
@@ -7,20 +7,19 @@ output is: 10101010 | |||
*/ | |||
#include "PortIOE.h" | |||
#include "PortRead_MCP23S17.h" | |||
#include "Scanner_IOE.h" | |||
#include "PortMCP23S17.h" | |||
const uint8_t PortIOE::DEVICE_ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded | |||
PortIOE portB(1, 0); | |||
PortIOE portB(1); | |||
PortRead_MCP23S17 portBRead(portB, ~0); | |||
PortMCP23S17 portBRead(portB, ~0); | |||
void setup() | |||
{ | |||
uint8_t portBState; //bit pattern | |||
delay(6000); | |||
portBRead.begin(LOW); | |||
portBRead.begin(HIGH); //HIGH or LOW, not matter | |||
portBState = portBRead.read(); | |||
Keyboard.print("portBState = "); |
@@ -1,29 +1,27 @@ | |||
/* unit test for PortWrite_MCP23S17 | |||
Picture of hardware is in unit_tests/PortRead_MCP23S17/PortRead_MCP23S17_bb.JPG | |||
/* unit test for PortMCP23S17 | |||
Picture of hardware is in unit_tests/PortMCP23S17_read/PortMCP23S17_bb.JPG | |||
The setup is an MCP23S17 I/O expander on a Teensy LC controller. | |||
MCP23S17 port-A GPIO pins are not connected to anything. | |||
Port-A GPIO-pin ouputs alternate between 0 and 3.3 volts. | |||
Use a volt meter to measure port-A GPIO-pin outputs. | |||
MCP23S17 on 3.3v does not output enough power to reliable light LEDs | |||
LED lights w/o resistor | |||
LED not light with 56 ohm resistor | |||
OR low-voltage LED, with forward voltage less than 2 volts. | |||
*/ | |||
#include "PortIOE.h" | |||
#include "PortWrite_MCP23S17.h" | |||
#include "PortMCP23S17.h" | |||
const uint8_t PortIOE::DEVICE_ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded | |||
PortIOE portA(0, 0); | |||
PortIOE portA(0); | |||
PortWrite_MCP23S17 portAWrite(portA); //PortAWrite needed for begin() | |||
PortMCP23S17 portAWrite(portA, 0); //PortAWrite needed for begin() | |||
//const uint8_t GPIOA = 0x12; //LEDs are on port A | |||
void setup() | |||
{ | |||
delay(6000); | |||
portAWrite.begin(); | |||
//Keyboard.print("start blinking"); | |||
portAWrite.begin(LOW); //HIGH or LOW, not matter if readPins=0 | |||
Keyboard.print("start writing"); | |||
} | |||
void loop() |