PCF8583 RTC Programming problem

marzan

Senior Member
Hello. I am trying to use a PCF8583 RTC in timer mode.

Here is the data sheet: http://www.nxp.com/documents/data_sheet/PCF8583.pdf


I can`t seem to get the appropriate 90 second output ( in hundredths of a second)

Here is the code I am using. It is just a test program to see if i can get the output into variables

Code:
symbol slvAddrWR = $A0  ' I2C write address
symbol slvAddrRD = $A1  ' I2C read address

MAIN:

	PAUSE 1000

  	i2cslave slvAddrWR, i2cslow, i2cbyte		'Initialize I2C-7SEG
  	
  	writei2c 8,(%00000001)		; alarm control registers and clock mode (08h)
	pause 10
						;bit7 	enable alarm interrupt
						;bit6		timer alarm
						;bit5/4	clock alarm 00= no clock alarm
						;bit3		timer interrupt enable
						;bit2/1/0  	timer function  001= hundredths of a second
							
												
	writei2c 0,(%00000100)					;timer function to 99 seconds
									;to enable %xx0xx1xx
						
	
						

	do
	readi2c 1, (b1,b2,b3,b4,b5,b6,b7,b8,b9)
	pause 460
	debug
	loop
any suggestions are appreciated.

Marz
 

nick12ab

Senior Member
I can`t seem to get the appropriate 90 second output ( in hundredths of a second)
Please describe what you do get - that will often result in an immediate solution to your problem as problems can often be diagnosed immediately from the symptoms.

Code:
symbol slvAddrWR = $A0  ' I2C write address
symbol slvAddrRD = $A1  ' I2C read address
The PDF states the following:
Slave addresses: A1h or A3h for reading, A0h or A2h for writing
The A0 pin determines which addresses to use so make sure that the A0 pin is correctly connected to Vdd or Vss. Also, you don't need to specify both addresses as the PICAXE automatically changes the address for you when doing a read or write operation. Therefore you only need one i2cslave command and you only need to use either $A0 or $A1 and it doesn't matter which one you use.
 

westaust55

Moderator
At a quick glance:
The timer (location 07h) is enabled by setting the control and status register to XX0X X1XX.

The control and status register is at address $00
Bit 5 is low for clock modes and bit 2 is high to enable alarm control register (memory location 08h is the alarm control register)

Suspect you need to write to location $00 first to enable the Alarm control register.

then you can set the Alarm control register at location $08

The actual timer is at location $07 (counts form 0 to 99) at the increments set by the value in location $08 (hundredths of a second in your case).

Once the timer has counted to 1 second it sets the timer flag (LSB of control and status register) but you are not reading back in location $00, your i2c data input starts at location $01, so you do not see the event.

If I read correctly, seems that you must in the PICAXE program reset the flag bit in the control and status register and keep the count yourself for 90 increments.


Finally, you should ideally be using the newer i2c related commands hi2csetup, hi2cin and hi2cout rather than the now deprecated commands which the PE converts where necessary to the newer commands.
 
Last edited:

marzan

Senior Member
Thanks for the replies guys. Went to set up my axe091 to check everything and think it might be something to do with the board. Plugged everything in and the mouse shot off to the top right corner of my screen . after trying a few things I discovered that it only does it when the 28x2 is inserted. I didn`t have another one handy, so I tried a 20x2 and the mouse took off to the bottom Lh corner! something screwy going on. I will have to investigate on the weekend.
Thanks again for ther replies.

Marz
 

hippy

Technical Support
Staff member
Plugged everything in and the mouse shot off to the top right corner of my screen
There's a Windows oddity that it may sometimes detect a serial device as a 'pointing device'. A look in Device Manager might reveal if it has and a re-boot might resolve that.
 

nick12ab

Senior Member
There's a Windows oddity that it may sometimes detect a serial device as a 'pointing device'. A look in Device Manager might reveal if it has and a re-boot might resolve that.
If the serial port just happens to receive the correct pulses then Windows will think you've connected a serial mouse. Happened to me once.
 

marzan

Senior Member
i have moved over to the laptop to overcome comm port issues. i had tied low A0 on the chip.

Code:
symbol slvAddrWR = $A0  ' I2C write address

MAIN:

	PAUSE 1000

  	i2cslave slvAddrWR, i2cslow, i2cbyte		'Initialize I2C-7SEG
  	
  	writei2c 0,(%00000100)					;timer function to 99 seconds
									;to enable %xx0xx1xx
  	
  	writei2c 8,(%00000001)		; alarm control registers and clock mode (08h)
	pause 10
						;bit7 	enable alarm interrupt
						;bit6		timer alarm
						;bit5/4	clock alarm 00= no clock alarm
						;bit3		timer interrupt enable
						;bit2/1/0  	timer function  001= hundredths of a second
													

	do
	readi2c 0, (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9)
	debug
	pause 10
	loop
The above code now runs :))

here`s what i see happening :
b0 starts at 00000100 and then changes to 00000101 after a second.You were right westaust55 that it would reset after a second.
b1 shows count in hundredths
b2 shows seconds
b3 shows minutes
...
b7 shows hundredths.
b8 00000001
b9 11110111


then I had a lightbulb moment. I changed to this : writei2c 8,(%00000010) and the count on b7 went to 100 seconds counting in seconds. Seems I cant do what I want. I wanted to make a stopwatch accurate to a tenth of a second to last around 100 seconds. b2 to b5 could give me what I am after, but i can`t seem to figure out how to reset the clock. If I run the same code twice, i find that the clock does not reset. I tried writei2c 4,(%00000000) but it dosent reset the clock. Any ideas?

Marz.
 

marzan

Senior Member
Maybe I can use the "power on reset" to do what I want. maybe power it through a transistor set with a pin from the picaxe?
 

westaust55

Moderator
Try
1. turn off the timer by writing $00 to control register $08
2. writing the value zero ($00) into the timer registers $01 to $06 inclusive.
3. when ready for next timing event, turn on the timer by writing $04 (%00000100) to control register $08
 

marzan

Senior Member
Talk about the most basic mistake I could make. Forgetting I could write to the timer registers. That got it working. Thanks Westaust55 ,Nick12ab, and Hippy.

Marz.
 

hippy

Technical Support
Staff member
There's a Windows oddity that it may sometimes detect a serial device as a 'pointing device'. A look in Device Manager might reveal if it has and a re-boot might resolve that.
Rather coincidentally I had this happen today. After a re-boot everything was working okay except every few seconds the mouse cursor would 'disappear', a jiggle would show it had jumped off the the bottom right of the screen.

If I hadn't recalled discussing this I'd probably not have worked out what was going on so quickly ! I'd left a PICAXE outputting DEBUG information plugged in when I re-booted and that was problem. This was using an AXE026 physical RS232 cable so that rather confirms it's not an AXE027 issue but a Windows one. Turning the PICAXE off, re-booting, fixed the problem.
 
Top