Jestin_cubetech
Advanced Member level 1
- Joined
- Jun 24, 2012
- Messages
- 499
- Helped
- 76
- Reputation
- 152
- Reaction score
- 73
- Trophy points
- 1,328
- Activity points
- 3,697
MCP23017 Input Reading Problem
MCP23017 I2C I/O Expander Input Reading Problem.
data output
input reading
MCP23017 I2C I/O Expander Input Reading Problem.
Code:
write PORTA //it works fine
i2c_waitForIdle();
i2c_start();
i2c_write(MCP_WRITE); // Opcode write mode MCP_WRITE=0x40
i2c_write(IODIRA); // set port A as outputs IODIRA = 0x0
i2c_write(0x0); //set port is output
i2c_stop();
i2c_waitForIdle();
i2c_start();
i2c_write(MCP_WRITE); // Opcode write mode MCP_WRITE=0x40
i2c_write(GPIOA); // set port A as outputs GPIOA = 0x12
i2c_write(0x55); //set output 0x55
i2c_stop();
//Problem is Here! PORTA Reading is not working.
---------------------------------------------------------------------------------------------
i2c_waitForIdle();
i2c_start();
i2c_write(MCP_WRITE); // Opcode write mode MCP_WRITE=0x40
i2c_write(IODIRA); // set port A as outputs IODIRA = 0x0
i2c_write(0xff); //set port is input
i2c_stop();
i2c_waitForIdle();
i2c_start();
i2c_write(MCP_WRITE);
i2c_repStart();
i2c_write(MCP_READ); // Opcode read mode
i2c_write(GPIOA);
value=i2c_read(1); //ACK
i2c_stop();
return value;
data output
input reading
Last edited: