This repo is archived. You can view files and clone it, but cannot push or open issues or pull requests.
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-11 23:03:00 +00:00
|
|
|
uint8_t portState; //bit wise
|
|
|
|
|
2016-09-11 22:45:52 +00:00
|
|
|
digitalWrite(SS, LOW); //enable Slave Select
|
|
|
|
SPI.transfer(command); //write command todo also read command?
|
|
|
|
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
|
|
|
}
|