Archived
1
0

change Port_MCP23S17, add slaveSelect to constructor parameter

This commit is contained in:
wolfv6 2016-11-16 08:29:51 -07:00
parent df4abb3808
commit 45674eb9b9
4 changed files with 17 additions and 16 deletions

View File

@ -12,11 +12,11 @@ uint8_t Port_MCP23S17::transfer(const uint8_t command, const uint8_t registerAdd
uint8_t portState; //bit pattern
SPI.beginTransaction( SPISettings(5000000, MSBFIRST, SPI_MODE0) ); //control SPI bus, 5 MHz
digitalWrite(SS, LOW); //enable Slave Select
digitalWrite(slaveSelect, LOW); //enable Slave Select
SPI.transfer(command); //write or read command
SPI.transfer(registerAddr); //register address to write data to
portState = SPI.transfer(data); //write data, read portState
digitalWrite(SS, HIGH); //disable Slave Select
digitalWrite(slaveSelect, HIGH); //disable Slave Select
SPI.endTransaction();
return portState;
@ -26,8 +26,8 @@ uint8_t Port_MCP23S17::transfer(const uint8_t command, const uint8_t registerAdd
*/
void Port_MCP23S17::beginProtocol()
{
pinMode(SS, OUTPUT); //configure controller's Slave Select pin to output
digitalWrite(SS, HIGH); //disable Slave Select
pinMode(slaveSelect, OUTPUT); //configure controller's Slave Select pin to output
digitalWrite(slaveSelect, HIGH); //disable Slave Select
SPI.begin();
}

View File

@ -9,8 +9,7 @@
write pins are connected to matrix Row (strobe pin) or LED.
readPins are connected to matrix column to read which keys are pressed.
Slave Select is hardcoded to Arduino Pin 10.
Arduino Pin 10 avoids the speed penalty of digitalWrite.
slaveSelect is Arduino-pin number connected to pin 11 (CS a.k.a. SS).
Instantiation
------------
@ -36,14 +35,15 @@ MCP23S17 data sheet
class Port_MCP23S17 : public PortInterface
{
private:
const uint8_t slaveSelect; //controller-pin number
const uint8_t deviceAddr;
const uint8_t portNum; //port identification number
uint8_t outputVal; //bit pattern for strobe and LEDs
const uint8_t readPins; //bit pattern, IODIR 0=output, 1=input
uint8_t transfer(const uint8_t command, const uint8_t registerAddr, const uint8_t data);
public:
Port_MCP23S17(const uint8_t deviceAddr, const uint8_t portNum, const uint8_t readPins)
: deviceAddr(deviceAddr), portNum(portNum), outputVal(0), readPins(readPins) {}
Port_MCP23S17(const uint8_t slaveSelect, const uint8_t deviceAddr, const uint8_t portNum, const uint8_t readPins)
: slaveSelect(slaveSelect), deviceAddr(deviceAddr), portNum(portNum), outputVal(0), readPins(readPins) {}
void beginProtocol();
void begin(const uint8_t activeState);
virtual void writeLow(const uint8_t pin);

View File

@ -6,7 +6,7 @@
#include <PortWriteInterface.h>
/* Port_ShiftRegs
slaveSelect is controller-pin number connected to shift register RCLK pin a.k.a. SS or ST
slaveSelect is Arduino-pin number connected to shift register RCLK pin a.k.a. SS or ST
*/
class Port_ShiftRegs : public PortWriteInterface
{

View File

@ -47,8 +47,9 @@ LED_uC LED_capsLck(21);
// --------------- RIGHT SCANNER ---------------
const uint8_t IOE_ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded
Port_MCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 ); //for read
Port_MCP23S17 portB(IOE_ADDR, 1, 0); //for strobe
const uint8_t slaveSelect = 10;
Port_MCP23S17 portA(slaveSelect , IOE_ADDR, 0, 1<<0 | 1<<1 ); //for read
Port_MCP23S17 portB(slaveSelect , IOE_ADDR, 1, 0); //for strobe
Scanner_IOE scanner_R(LOW, portB, portA);