keybrd library is an open source library for creating custom-keyboard firmware.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
Repozitorijs ir arhivēts. Tam var aplūkot failus un to var klonēt, bet nevar iesūtīt jaunas izmaiņas, kā arī atvērt jaunas problēmas/izmaiņu pieprasījumus.

MCP23S17_read.ino 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* this works
  2. The setup is an MCP23S17 I/O expander on a Teensy LC controller.
  3. MCP23S17 port B pins are alternately grounded and energized.
  4. portBState is a bitwise reading of port B.
  5. output is: 10101010
  6. posted on http://arduino.stackexchange.com/questions/tagged/spi
  7. http://arduino.stackexchange.com/questions/28792/reading-an-mcp23s17-i-o-expander-port-with-the-arduino-spi-library
  8. */
  9. #include <SPI.h>
  10. const uint8_t ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded
  11. const uint8_t OPCODE_READ = (ADDR << 1 | 0x01); //MCP23S17 opcode read has LSB set
  12. const uint8_t IODIRB = 0x01;
  13. const uint8_t GPIOB = 0x13;
  14. uint8_t portBState = 0; //bit wise
  15. void setup()
  16. {
  17. Serial.begin(9600);
  18. delay(1000);
  19. pinMode(SS, OUTPUT); //configure controller's Slave Select pin to output
  20. digitalWrite(SS, HIGH); //disable Slave Select
  21. SPI.begin();
  22. //IODIRB register is already configured to input by default
  23. SPI.beginTransaction(SPISettings (SPI_CLOCK_DIV8, MSBFIRST, SPI_MODE0)); //gain control of SPI bus
  24. digitalWrite(SS, LOW); //enable Slave Select
  25. SPI.transfer(OPCODE_READ); //read command
  26. SPI.transfer(GPIOB); //register address to read data from
  27. portBState = SPI.transfer(0); //save the data (0 is dummy data to send)
  28. digitalWrite(SS, HIGH); //disable Slave Select
  29. SPI.endTransaction(); //release the SPI bus
  30. Serial.println(portBState, BIN); //should print 10101010
  31. }
  32. void loop() { }