|
|
View previous topic :: View next topic |
Author |
Message |
Richi Guest
|
MCP23016 |
Posted: Thu Jul 13, 2006 10:33 am |
|
|
Hi Friends,
want to use a MCP23016. Now I think my code is o.k... I measured with a oszilloskop and canīt find an error, The initial sequenz (I/O direction) is sended but if I read from any registerpair I always get 0xFF in the WATCH window- as I also can se on the oszilloskop. So the adress and everything is o.k. I also get an acknolage.
Second: the INT Pin is always low- but maybe it is because the part is not initialized?
(Is it really necessary to give a 20ĩs delay between every Write/read? What about using the Fast-mode?)
The Code:
void Write_I2C_MCP ( int MCP_Commando, long MCP_Data )
{
MCP_Data_L = make8(MCP_Data,0);
MCP_Data_H = make8(MCP_Data,1);
I2C_start();
delay_us(20);
I2C_write( 0x40 ); // Adresse
delay_us(20);
I2C_write( MCP_Commando );
delay_us(20);
I2C_write( MCP_Data_H );
delay_us(20);
I2C_write( MCP_Data_L );
delay_us(20);
I2C_stop();
delay_us(20);
}
int Read_I2C_MCP ( int MCP_Commando )
{
I2C_start();
delay_us(20);
I2C_write( 0x40 ); // Adresse
delay_us(20);
I2C_write( MCP_Commando );
delay_us(20);
I2C_write( 0x41 ); // Adresse
delay_us(20);
MCP_Data_lesen_H = I2C_read();
delay_us(20);
MCP_Data_lesen_L = I2C_read();
delay_us(20);
I2C_stop();
delay_us(20);
return(MCP_Data_lesen_L, MCP_Data_lesen_H);
}
#INT_EXT
void isr_ext()
{
NOP;
}
void main (void)
{
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);
EXT_INT_EDGE(H_TO_L);
Write_I2C_MCP ( 0x04, 0x0000 );
Write_I2C_MCP ( 0x0A, 0x0101 );
Write_I2C_MCP ( 0x06, 0xC700 );
delay_ms(1);
Write_I2C_MCP ( 0x02, 0x0000 );
for (;;)
{
Read_I2C_MCP ( 0x06 );
Read_I2C_MCP ( 0x08 );
Write_I2C_MCP ( 0x00, 0xFF00 );
}
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 13, 2006 11:34 am |
|
|
There's a driver for the MCP23016 in the code forum:
http://www.ccsinfo.com/forum/viewtopic.php?t=21797
Also, if you had logged in, then you could delete the double post
that you made. Guests can't delete their extra posts. |
|
|
Richi Guest
|
|
Posted: Fri Jul 14, 2006 7:21 am |
|
|
Hi PCM,
I already had seen this sample C-File. And I found out that my programm is nearly the same. But it didnīt work! WHY? After a third and fourt compare I found out that i forgot to send a new start condition when reading...
Thanks |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|