[En-Nut-Discussion] TWI and Philips PCF8583 Real Time Clock

Gediminas Simanskis gedas at post.tvk.lt
Wed May 14 06:14:52 CEST 2003


> Hi,
> 
> That was quite informative.
> 
> Has anyone got some sample code that uses TWIF.c/h that they would be
> willing to share to help me understand how the EtherNut routines work?
> 
> Cheers Douglas
> 

code work with AT24C256 & FRAM 24C256

int readEEPROM(u_char sla,u_int addr,void *rxxdata,u_short len)
{
   u_char adata[2];
   
   adata[0] = (u_char)(addr>>8);
   adata[1] = (u_char) addr;

   TwMasterTransact(sla, adata, 2,rxxdata, len, 0);
   
   return 0;
}

int writeEEPROM(u_char sla,u_int addr,void *txdata,u_short len)
{  
   u_char data[128];
   
   data[0] = (u_char)(addr>>8);
   data[1] = (u_char) addr; 
  
   memcpy(&data[2],txdata,len);      
   TwMasterTransact(sla, data,len+2, 0, 0, 0); 
   _delay_loop_2(10000); 

   return 0 ;
}



More information about the En-Nut-Discussion mailing list