I'm working to develop a simple code for MCP23017 that I want to use to run LCD128x64.
I was succeeded to set IODIRB
as output and blink LED as a test.
Now I want to read the pin state, but I couldn't. Here's my code. I'm using the nice twi library that comes with Wire library.
uint8_t mcp23017_read(uint8_t add_reg){
uint8_t data;
twi_writeTo(MCP23017_ADD,add_reg,2,1,0);
twi_readFrom(MCP23017_ADD,data,1,1);
return data;
}
I've tried this version too:
uint8_t *mcp23017_read(uint8_t add_reg){
uint8_t data[1];
twi_writeTo(MCP23017_ADD,add_reg,2,1,0);
twi_readFrom(MCP23017_ADD,data,1,1);
return *data;
}
==================================================
Here's Arduino call function:
void loop() {
// put your main code here, to run repeatedly:
data = mcp23017_read(GPIOB);
Serial.println(data);
delay(100);
}