Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] MCP23017 I2C I/O Expander Input Reading Problem

Status
Not open for further replies.

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.


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:

Re: MCP23017 Input Reading Problem

___________Problem solved !__________


mcp23017.png



Read Sequence

Code:
i2c_waitForIdle();
i2c_start();
i2c_write(MCP_WRITE);
i2c_write(reg); 
i2c_repStart();
i2c_write(MCP_READ); // Opcode read mode
value=i2c_read(0);  //ACK 
i2c_stop();   
return value;
 

Re: MCP23017 Input Reading Problem

___________Problem solved !__________


View attachment 76745



Read Sequence

Code:
i2c_waitForIdle();
i2c_start();
i2c_write(MCP_WRITE);
i2c_write(reg); 
i2c_repStart();
i2c_write(MCP_READ); // Opcode read mode
value=i2c_read(0);  //ACK 
i2c_stop();   
return value;

Hi,
I'm having problem with reading continuously from the MCP using I2C, do you have any suggestions?
 

use interrupt option it helps to reduce the unwanted read.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top