inter-picaxe communication of DS1307 data

DBoyd

New Member
Hello,

The following code does not transmit the DS1307 RTC information correctly.
With a few changes, (the pin # and display locations), I was able to display the clock data(Hours and minutes) on a serial LCD.

Now I am trying to transmit the data to another picaxe, both 18m2+, without success.
The hex variables, b10 b11 b12, are transmitting and displaying correctly. The clock data is not.

The receiving picaxe does nothing but receive serial communication and control the display.
The sending picaxe does nothing but receive the clock data and send serial communication to the LCD picaxe.

The LCD displays 00:80. (no matter what time it is)

Can anyone tell me what I'm doing wrong?

Thanks in advance.

DBoyd

Code:
symbol mins = b1           'for DS1307 data
symbol hour = b2           'for DS1307 data 
                           'b10  is variable for rtemp 
                           'b11 ftemp
                           'b12 stemp

hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte       'setup i2c
pause 50


main:


b10 = $5a                'fixed variable for testing
b11 = $50                'fixed variable for testing
b12 = $55                'fixed variable for testing


bintoascii b10, b21,b22,b23    'changed to send ASCII to parallel LCD
bintoascii b11, b24,b25,b26    'changed to send ASCII to parallel LCD
bintoascii b12, b5,b13,b14     'changed to send ASCII to parallel LCD

hi2cin b0, (mins,hour)         ; Receive information from clock

bcdtoascii mins, b17, b18       'minutes
bcdtoascii hour, b15, b16       'hours
   		     
 	serout c.1, t2400, (b22,b23,b25,b26,b13,b14,b15,b16,b17,b18) 	 'sent to picaxe controlling parallel LCD in byte mode 
pause 1000

goto main
 
Last edited by a moderator:

westaust55

Moderator
First problem:
Have you actually previously set the DS1307 with the time and set it to run ?

If the only value you see is "80", then the DS1307 is stopped.
keep in mind that you currently have b0 = 0 and thus reading the seconds (register 0) and minutes (register 1).

From the DS1307 datasheet:
Bit 7 of Register 0 is the clock halt (CH) bit. When this bit is set to 1, the oscillator is disabled. When cleared to 0, the oscillator is enabled. On first application of power to the device the time and date registers are typically reset to 01/01/00 01 00:00:00 (MM/DD/YY DOW HH:MM:SS). The CH bit in the seconds register will be set to a 1. The clock can be halted whenever the timekeeping functions are not required, which minimizes current (IBATDR).
Bit7 when set to 1 and the clock not set results in a value of %10000000 or $80 which by BCD conversion = "80"


Second problem:
you are, as per comments in a recent thread, in the Hi2cIN command still using a variable (ie b0) as the register location for the DS1307.
if you have not set b0 then it will = 0 and you would be reading in the seconds and minutes instead of the minutes and hours.

try:
Code:
hi2cin [b][COLOR="#FF0000"]1[/COLOR][/b], (mins,hour)         ; Receive information from clock

bcdtoascii mins, b17, b18       'minutes
bcdtoascii hour, b15, b16       'hours
You are using the t2400 baud rate parameter. This is for True polarity.
In this case it would be better to have a HIGH C.1 as an initialisation command at the start of the program.

Otherwise try the N2400 baud rate parameter (for iNverted signal polarity).

Are you using the default clock speed (= 4 MHz). if other than 4 MHz you definitely must add the clock speed as a suffix such as T2400_4 or N2400_4. Change the 4 to the actual clock speed.

Can you please post the program for the receiving 18M2.


Also, for futrure reference, as oper this thread (a sticky "Read-Me-First" note at the top of this forum first page):
http://www.picaxeforum.co.uk/showthread.php?7679-Read-Me-First!
please add the [code] and [/code] tags around your programs when there is more than a couple of lines involved.
 
Last edited:

DBoyd

New Member
I'm very new at this and might not be understanding the full ramifications of your advice. Please bear with me.

Yes. I did program the clock/calender, and it was running correctly. There is a battery installed and it was holding time.

Hmm. I'm concerned that '80' might mean the clock is not holding it's program. I have it hooked up to the parallel LCD Picaxe and don't really want to tear down the set-up and reattach the serial LCD.

I will change 'hi2cin 0' to hicin 1' and give it a try, but I was trying to convert and send b1 and b2.


You are using the t2400 baud rate parameter. This is for True polarity.
In this case it would be better to have a HIGH C.1 as an initialization command at the start of the program.
Yes. I am using True polarity. Setting C.1 as High seems counter-intuitive to me. I have a pull down resistor on that pin. And wouldn't setting it High negate any initialization pulse sent by the SPI?
And wouldn't setting C.1 High cause the Interrupt at the other end to lock-up the program on the other Picaxe?

Yes. I am using the default clock speed.

Here is the receiving code. It's kind of long. More than I wanted to post, but you asked for it. :)

Code:
 symbol test = b9
symbol instruct = b10
symbol display = b0 
symbol position = b20 
'b22 roof temp tens
'b23 roof temp units
'b25 f temp tens
'b26 f temp units
'b3 Vsun 
'b4 Vbat


'b15 tens-hour 
'b16 units-hour
'b17 tens-minute
'b18 units-minute


INITIALIZE:

dirsB = %11111111
low c.1, c.0                           'write and instruction mode
low c.2                      
b10 = %00000001                        'clear display
outpinsB = instruct
pulsout c.2, 1

b10 = %00000110                        'shift cursor to right/increment address
outpinsB = instruct
pulsout c.2, 1

b10 = %00001111                        'display on/cursor on/ blink on
outpinsB = instruct
pulsout c.2, 1 

b10 = %00010100                        'cursor moves right
outpinsB = instruct
pulsout c.2, 1

b10 = %00111000                        'sets 8 bit parallel/ 2x40(4x20) display, 5x8 dot characters
outpinsB = instruct
pulsout c.2, 1



text:	

position = $80                      'beginning of 1st line
gosub position1

eeprom 1,("Next H2O in 00:00")	; save values in EEPROM 'Next H2O in 00:00'

	for b1 = 1 to 17		      ; start a loop
	  read b1,b0			; read value from EEPROM
outpinsB = display		  
gosub pulse
next b1			            ; next character	


text1: 
                                  
position = $BC                     'beginning of 2nd line
gosub position1

eeprom 18,("VSun=")	           ; save values in EEPROM  'VSun='
	for b1 = 18 to 22		     ; start a loop
	  read b1,b0		     ; read value from EEPROM
outpinsB = display		  
gosub pulse
next b1			           ; next character	


text2:

position = $ca                     'middle of 2nd line
gosub position1 

eeprom 23,("VBat=")	           ; save values in EEPROM  'VBat='
	for b1 = 23 to 27		     ; start a loop
	  read b1,b0		     ; read value from EEPROM
outpinsB = display		  
gosub pulse
next b1
 
text3:
                                   
position = $94                     'beginning of 3rd line
gosub position1

eeprom 28,("RTemp=")	           ; save values in EEPROM   'RTemp=' 
	for b1 = 28 to 33		     ; start a loop
	  read b1,b0		     ; read value from EEPROM
outpinsB = display		  
gosub pulse
next b1	
 
 
text4:

position = $9e                     'middle of 3rd line
gosub position1

eeprom 34,("FTemp=")	           ; save values in EEPROM   'FTemp='
	for b1 = 34 to 39		     ; start a loop
	  read b1,b0		     ; read value from EEPROM
outpinsB = display		  
gosub pulse
next b1
 
                                  
text5:

position = $d4                     'beginning of 4th line
gosub position1
 
eeprom 40,("Set Temp=")	           ; save values in EEPROM   'Set Temp='
	for b1 = 40 to 48		     ; start a loop
	  read b1,b0	           ; read value from EEPROM
outpinsB = display		  
gosub pulse
next b1
  
                               
text6:

position = $e1                     'middleish of 4th line
gosub position1

eeprom 49,("00:00")	           ; save values in EEPROM  '00:00' 
	for b1 = 49 to 53            ; start a loop
	  read b1,b0		     ; read value from EEPROM
outpinsB = display		  
gosub pulse
next b1



test1:	

setint %01000000,%01000000

position = $9a                     ' Rtemp 
gosub position1

display = b22	
'Rtemp	     
outpinsB = display		  
gosub pulse                         'Rtemp Variable = b22  

display = b23	
'Rtemp	     
outpinsB = display		  
gosub pulse                         'Rtemp Variable = b23  


position = $a4                     ' Ftemp value 164
gosub position1
display = b25		     
outpinsB = display		      
gosub pulse                         'FTemp variable = b25

display = b26	
'Rtemp	     
outpinsB = display		  
gosub pulse                         'Rtemp Variable = b26  


position = $dd                     ' Stemp value 222
gosub position1
display = b12		     
outpinsB = display		      
gosub pulse                         'STemp variable = b12

display = b13	
'Rtemp	     
outpinsB = display		  
gosub pulse                         'Stemp Variable = b13  



Time1:

position = $e1                   'instruction mode
gosub position1

display = b15		     
outpinsB = display		  
gosub pulse                         'Time Variable = b17  'maybe change to Word


position = $e2                   'instruction mode
gosub position1

display = b16     
outpinsB = display		  
gosub pulse                         'time Variable = b18  'maybe change to Word



position = $e4                      'instruction mode
gosub position1

display = b17		     
outpinsB = display		  
gosub pulse                         'Time Variable = b15  


position = $e5                      'instruction mode
gosub position1

display = b18	     
outpinsB = display		  
gosub pulse                         'time Variable = b16  


Voltage: 

position = $c1                      'instruction mode 193
gosub position1

display = b3	     
outpinsB = display		  
gosub pulse                         'Vsun Variable = b3  


position = $ce                      'instruction mode 206
gosub position1

display = b4	     
outpinsB = display		  
gosub pulse                         'Vbat Variable = b4  


goto test1

interrupt: 
serin c.6, t2400, b22,b23,b25,b26,b12,b13,b15,b16,b17,b18,b3,b4
'setint %01000000,%01000000				    
 

position1: 
low c.0 
outpinsb= position
pulsout c.2, 1
return


pulse: 
high c.0
pulsout c.2, 1
return
Thanks again.
 
Last edited:

westaust55

Moderator
A few starting comments:

1. I do not see a command to pulse output c.1 to cause the interrupt before the receiver starts looking for serial data.
2. There will need to been a short pause between the transmitter/senders interrupt pulse and the start of SEROUT to give the receiver time to jump and set up the SERIN command.
At 4 MHz start with pause 1000 .
3. In the receiver code there is no return command at the end of the interrupt routine. Your code will call through into the Position1: routine. Or is that intended.
4. When using True polarity for serial comms the idle state is high. If you hold the line low then SERIN will see that as garbage and may get confused. If you set the output high you can always pulse low and detect the high to low state in the receiver interrupt setup.

As a suggestion, until you know the RTC is working and you are reading the expected data/time back just use the first PICAXE and send the values to the PE terminal screen with SERTXD or SEROUT.
 
Top