keybrd library is an open source library for creating custom-keyboard firmware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

PortMCP23S17.cpp 696B

12345678910111213141516
  1. #include "PortMCP23S17.h"
  2. /* transfer() writes data to registerAddr, reads portSate from registerAddr, and returns portState.
  3. */
  4. uint8_t PortMCP23S17::transfer(const uint8_t command, const uint8_t registerAddr, const uint8_t data)
  5. {
  6. uint8_t portState; //bit pattern
  7. digitalWrite(SS, LOW); //enable Slave Select
  8. SPI.transfer(command); //write or read command
  9. SPI.transfer(registerAddr); //register address to write data to
  10. portState = SPI.transfer(data); //write data, read portState
  11. digitalWrite(SS, HIGH); //disable Slave Select
  12. return portState;
  13. }