#include #include #include Adafruit_MCP23017 mcp0; Adafruit_MCP23017 mcp1; #define MCP23017_PORTA 0x00 #define MCP23017_PORTB 0x01 unsigned int add; unsigned char readData; int lineCount; void setup() { Serial.begin(115200); mcp0.begin(0); // address 0: ADDRESS BUS A0-A7 => GPB0-7, A8-A14 => GPA0-7 mcp1.begin(1); // address 1: DATA BUS Q0-Q7 => GPB0-7, ^CS12 => GPA0 // ADDRESS BUS mcp0.pinMode8(MCP23017_IODIRA, 0x00); mcp0.pinMode8(MCP23017_IODIRB, 0x00); // control line:IIIIIIIO mcp1.pinMode8(MCP23017_IODIRA, 0xfc); // DATA BUS mcp1.pinMode8(MCP23017_IODIRB, 0xff); add = 0x4000; lineCount = 0; } void loop() { if (lineCount % 16 == 0) { Serial.print("\n"); printHex(add, 4); Serial.print(":"); } // ^CS12 disable mcp1.writeGPIO(MCP23017_PORTA, 0xff); // address mcp0.writeGPIO(MCP23017_PORTA, add>>8); mcp0.writeGPIO(MCP23017_PORTB, add&0xff); // ^CS12 enable mcp1.writeGPIO(MCP23017_PORTA, 0xfe); // GPIOB readData = mcp1.readGPIO(1); // ^CS12 disable mcp1.writeGPIO(MCP23017_PORTA, 0xff); //Serial.print(readData, HEX); printHex(readData, 2); Serial.print(" "); add++; lineCount++; if (lineCount > 0x7fff) { Serial.print("\n\nend"); delay(10); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_mode(); } } void printHex(int num, int precision) { char tmp[16]; char format[128]; sprintf(format, "%%.%dX", precision); sprintf(tmp, format, num); Serial.print(tmp); }