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

Pearless Douglas.Pearless at pearless.co.nz
Thu May 15 23:20:47 CEST 2003


Hi Again,

Thanks for the code.

I have been trying to write to the PCF8583, but I always get a rc=-1 from my
initRTC routine, I am puzzled!

I have noticed that there are NO pulses on SCL or SDA from the EtherNut
(logic probe).

I have triple checked the wiring, and I know the PCF8583 is alive as it is
generating 1Hz pulses on its interrupt line just like it should when it
powers up uninitialised.

I'd appreciate some feedback on my code, as I have stepped through it in
AVRStudio and all the parameters to the TWIMasterTransact seem to be
correct?

Code parts below

Cheers Douglas


int writeRTC(u_char sla,u_int addr,void *txdata,u_short len)
{
   u_char data[17]; // we are not using the balance of the 240 bytes of RAM

   data[0] = (u_char)(addr);
   memcpy(&data[1],txdata,len);
   return TwMasterTransact(sla, data,len+1, 0, 0, RTC_I2C_TIMEOUT);
}

int initRTC(u_char sla)
{
   /* the RTC starts off generating a 1Hz cycle on the Interrupt pin, so
before we enable interrupts we
    * need to set the stop counting flag of the control/status register,
then we can do what we like, e.g.
	* set the time for the very first time
	*/
	u_char data[1];  //yes an array of 1 is redundant, but I what consistency
	int rc;

	data[0] = 0b11001100;
	rc = writeRTC(sla,0,data,1);

   return rc;
}

My calling code snippet looks like:

...
#define RTC_I2C_ADDRESS 0x50 // this is the address of the Philips PCF8583
RTC
#define RTC_I2C_TIMEOUT 100  // this is the timeout in ms for the TWI / I2C
bus to get a response

...

    fputs("\nInit TWI Start", uart);
    fflush(uart);
    i = TwInit(0);
	if (i) fprintf(uart, "\nOOPS RC = %d!\n", i);
    fputs("\nInit TWI Stop", uart);
    fputs("\nInit RTC Start", uart);
    fflush(uart);
    i = initRTC((u_char)RTC_I2C_ADDRESS);
	if (i) fprintf(uart, "\nOOPS RC = %d!\n", i);
    fputs("\nInit RTC Stop", uart);
    fflush(uart);


The output on 'uart' is:

Init TWI Start
Init TWI Stop
Init RTC Start
OOPS RC = -1!

Init RTC Stop


-----Original Message-----
From: en-nut-discussion-admin at egnite.de
[mailto:en-nut-discussion-admin at egnite.de]On Behalf Of Gediminas
Simanskis
Sent: Wednesday, 14 May 2003 4:15 p.m.
To: en-nut-discussion at egnite.de
Subject: Re: [En-Nut-Discussion] TWI and Philips PCF8583 Real Time Clock




> 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 ;
}
_______________________________________________
En-Nut-Discussion mailing list
En-Nut-Discussion at egnite.de
http://www.egnite.de/mailman/listinfo/en-nut-discussion

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.481 / Virus Database: 277 - Release Date: 13/05/2003

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.481 / Virus Database: 277 - Release Date: 13/05/2003




More information about the En-Nut-Discussion mailing list