2016-09-11 22:45:52 +00:00
|
|
|
#include "PortMCP23S17.h"
|
|
|
|
|
2016-09-11 23:03:00 +00:00
|
|
|
/* transfer() writes data to registerAddr, reads portSate from registerAddr, and returns portState.
|
2016-09-11 22:45:52 +00:00
|
|
|
*/
|
2016-09-11 23:03:00 +00:00
|
|
|
uint8_t PortMCP23S17::transfer(const uint8_t command, const uint8_t registerAddr, const uint8_t data)
|
2016-09-11 22:45:52 +00:00
|
|
|
{
|
2016-09-17 21:47:37 +00:00
|
|
|
uint8_t portState; //bit pattern
|
2016-09-11 23:03:00 +00:00
|
|
|
|
2016-09-11 22:45:52 +00:00
|
|
|
digitalWrite(SS, LOW); //enable Slave Select
|
2016-09-12 06:28:27 +00:00
|
|
|
SPI.transfer(command); //write or read command
|
2016-09-11 22:45:52 +00:00
|
|
|
SPI.transfer(registerAddr); //register address to write data to
|
2016-09-11 23:03:00 +00:00
|
|
|
portState = SPI.transfer(data); //write data, read portState
|
2016-09-11 22:45:52 +00:00
|
|
|
digitalWrite(SS, HIGH); //disable Slave Select
|
2016-09-11 23:03:00 +00:00
|
|
|
|
|
|
|
return portState;
|
2016-09-11 22:45:52 +00:00
|
|
|
}
|