Richi Guest
|
MCP23016 |
Posted: Thu Jul 13, 2006 10:32 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 );
}
} |
|