CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

MCP23016

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Richi
Guest







MCP23016
PostPosted: Thu Jul 13, 2006 10:32 am     Reply with quote

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 );
}
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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