I going nuts here trying to interface a PICAXE-20X2 to a DS1302 (I know the 07 is easier via I2C but I have my reasons for using the 02, besides I bought 10 so I'm determined to use the damn things).
There seems to be no real guidence specifically for using the HSPI pins on the 20X2 (not to mention a specific 20X2 manual) and I can't find any code other than for the 08M which I just cannot convert. Do I have to use a crystal for example?? What are the correct hspisetup settings to get this to work??
I am a fairly accomplished electronics geek and hate to have to admit defeat here but there it is. All I need, please, is the very simple hook up and cut down code example and I'll take it from there - I can then come in from the windowsill.
Yes, I am running the correct version of the software and hav swopped out both chips just in case. Here's my pathetic attempt.....
To sum up....aaaaagggghhh!!!
Thanking you in advance dear reader.
'************************************************************
'Filename: DS1302_20X_Test
'Date: 01/12/2009
'File Version: V1.0
'Written by: N.Reburn
'Function: Write and read test to DS1307
'Target PICAXE: 20x
'************************************************************
'Pin B.0 =
'Pin B.1 = 24x8 LCD
'Pin B.2 =
'Pin B.3 =
'Pin B.4 =
'Pin B.5 = HSPI SDI to DS1302 leg 6 ---\
'Pin B.6 = |
'Pin B.7 = HSPI SCK to DS1302 leg 7 |-- Joined
'Pin C.0 = |
'Pin C.1 = HSPI SDO to DS1302 leg 6 ---/
'Pin C.2 =
'Pin C.3 =
'Pin C.4 =
'Pin C.5 =
'Pin C.6 =
'Pin C.7 = RST to DS1302 leg 5
'------------------------------------------------------------
; DS1302 RST Connection
Symbol RST = C.7
; LCD Connection
Symbol V_LCDPort=B.1
Symbol V_LCDData=N9600_8
;Time Variables
Symbol V_Year =B21
Symbol V_Day =B22
Symbol V_Month =B23
Symbol V_Date =B24
Symbol V_Hour =B25
Symbol V_Min =B26
Symbol V_Sec =B27
Symbol V_RTCon =B28
; Initial Times
V_Year=$99
V_Day=$06
V_Month=$07
V_Date=$16
V_Hour=$08
V_Min=0
V_Sec=0
'------------------------------------------------------------
PAUSE 100
SEROUT V_LCDPort,V_LCDData,(92,74,0,1) 'LED On
SEROUT V_LCDPort,V_LCDData,(92,64,32,48)
PAUSE 10
SEROUT V_LCDPort,V_LCDData,(92,66,32,34," Quantum InfoTech Ltd ")
SEROUT V_LCDPort,V_LCDData,(92,66,32,35," DS1302_20X_Test ")
SEROUT V_LCDPort,V_LCDData,(92,66,32,36," (C) 2010 ")
SEROUT V_LCDPort,V_LCDData,(92,66,32,37," V 1.10 ")
PAUSE 100
SEROUT V_LCDPort,V_LCDData,(92,74,0,0) 'LED Off
PAUSE 3000
SEROUT V_LCDPort,V_LCDData,(92,64,32,48)
PAUSE 100
'************************************************************
Gosub DispReset
Gosub Setup
Gosub Settime
Main:
Do
Gosub GetTime
'Pause 1000
Loop
End
'************************************************************
SetUp:
SEROUT V_LCDPort,V_LCDData,(92,66,39,39,"Setup...")
PAUSE 500
Input B.5
Output C.1
hspisetup spimode11e, spifast
'hspisetup spimode11e, spimedium
'hspisetup spimode11e, spislow
Return
'************************************************************
Settime: 'set the time
SEROUT V_LCDPort,V_LCDData,(92,66,39,39,"Set time >>>>")
Pause 500
High Rst 'enable data tx
'hspiout($8e,0) 'enable write
Low Rst 'reset RTC
High Rst 'ready for tx
'write all 8 RTC registers in burst mode
'hspiout($be,V_Sec,V_Min,V_Hour,V_Date,V_Month,V_Day,V_Year,0)
Low Rst 'reset RTC
Return
'************************************************************
Gettime: 'read the time from the RTC
SEROUT V_LCDPort,V_LCDData,(92,66,39,39,"Get time <<<<")
Pause 500
High Rst 'ready for tx
hspiout($bf) 'Read all 8 RTC registers in burst mode
hspiin(V_Sec,V_Min,V_Hour,V_Date,V_Month,V_Day,V_Year,V_RTCon)
Low Rst ' Reset RTC
SEROUT V_LCDPort,V_LCDData,(92,66,39,37,V_Date,"/")
SEROUT V_LCDPort,V_LCDData,(92,66,42,37,V_Month,"/")
SEROUT V_LCDPort,V_LCDData,(92,66,45,37,V_Year)
SEROUT V_LCDPort,V_LCDData,(92,66,39,38,V_Hour,":")
SEROUT V_LCDPort,V_LCDData,(92,66,42,38,V_Min,":")
SEROUT V_LCDPort,V_LCDData,(92,66,45,38,V_Sec)
Return
'************************************************************
DispReset:
'Add no scroll etc here
SEROUT V_LCDPort,V_LCDData,(92,66,32,32,"Date : / /")
SEROUT V_LCDPort,V_LCDData,(92,66,32,33,"Time : : :")
SEROUT V_LCDPort,V_LCDData,(92,66,32,34,"Sgnl :")
SEROUT V_LCDPort,V_LCDData,(92,66,32,35,"Sats :")
SEROUT V_LCDPort,V_LCDData,(92,66,32,36," ")
SEROUT V_LCDPort,V_LCDData,(92,66,32,37,"Date :")
SEROUT V_LCDPort,V_LCDData,(92,66,32,38,"Time :")
SEROUT V_LCDPort,V_LCDData,(92,66,32,39,"Stat :")
Return
'************************************************************
There seems to be no real guidence specifically for using the HSPI pins on the 20X2 (not to mention a specific 20X2 manual) and I can't find any code other than for the 08M which I just cannot convert. Do I have to use a crystal for example?? What are the correct hspisetup settings to get this to work??
I am a fairly accomplished electronics geek and hate to have to admit defeat here but there it is. All I need, please, is the very simple hook up and cut down code example and I'll take it from there - I can then come in from the windowsill.
Yes, I am running the correct version of the software and hav swopped out both chips just in case. Here's my pathetic attempt.....
To sum up....aaaaagggghhh!!!
Thanking you in advance dear reader.
'************************************************************
'Filename: DS1302_20X_Test
'Date: 01/12/2009
'File Version: V1.0
'Written by: N.Reburn
'Function: Write and read test to DS1307
'Target PICAXE: 20x
'************************************************************
'Pin B.0 =
'Pin B.1 = 24x8 LCD
'Pin B.2 =
'Pin B.3 =
'Pin B.4 =
'Pin B.5 = HSPI SDI to DS1302 leg 6 ---\
'Pin B.6 = |
'Pin B.7 = HSPI SCK to DS1302 leg 7 |-- Joined
'Pin C.0 = |
'Pin C.1 = HSPI SDO to DS1302 leg 6 ---/
'Pin C.2 =
'Pin C.3 =
'Pin C.4 =
'Pin C.5 =
'Pin C.6 =
'Pin C.7 = RST to DS1302 leg 5
'------------------------------------------------------------
; DS1302 RST Connection
Symbol RST = C.7
; LCD Connection
Symbol V_LCDPort=B.1
Symbol V_LCDData=N9600_8
;Time Variables
Symbol V_Year =B21
Symbol V_Day =B22
Symbol V_Month =B23
Symbol V_Date =B24
Symbol V_Hour =B25
Symbol V_Min =B26
Symbol V_Sec =B27
Symbol V_RTCon =B28
; Initial Times
V_Year=$99
V_Day=$06
V_Month=$07
V_Date=$16
V_Hour=$08
V_Min=0
V_Sec=0
'------------------------------------------------------------
PAUSE 100
SEROUT V_LCDPort,V_LCDData,(92,74,0,1) 'LED On
SEROUT V_LCDPort,V_LCDData,(92,64,32,48)
PAUSE 10
SEROUT V_LCDPort,V_LCDData,(92,66,32,34," Quantum InfoTech Ltd ")
SEROUT V_LCDPort,V_LCDData,(92,66,32,35," DS1302_20X_Test ")
SEROUT V_LCDPort,V_LCDData,(92,66,32,36," (C) 2010 ")
SEROUT V_LCDPort,V_LCDData,(92,66,32,37," V 1.10 ")
PAUSE 100
SEROUT V_LCDPort,V_LCDData,(92,74,0,0) 'LED Off
PAUSE 3000
SEROUT V_LCDPort,V_LCDData,(92,64,32,48)
PAUSE 100
'************************************************************
Gosub DispReset
Gosub Setup
Gosub Settime
Main:
Do
Gosub GetTime
'Pause 1000
Loop
End
'************************************************************
SetUp:
SEROUT V_LCDPort,V_LCDData,(92,66,39,39,"Setup...")
PAUSE 500
Input B.5
Output C.1
hspisetup spimode11e, spifast
'hspisetup spimode11e, spimedium
'hspisetup spimode11e, spislow
Return
'************************************************************
Settime: 'set the time
SEROUT V_LCDPort,V_LCDData,(92,66,39,39,"Set time >>>>")
Pause 500
High Rst 'enable data tx
'hspiout($8e,0) 'enable write
Low Rst 'reset RTC
High Rst 'ready for tx
'write all 8 RTC registers in burst mode
'hspiout($be,V_Sec,V_Min,V_Hour,V_Date,V_Month,V_Day,V_Year,0)
Low Rst 'reset RTC
Return
'************************************************************
Gettime: 'read the time from the RTC
SEROUT V_LCDPort,V_LCDData,(92,66,39,39,"Get time <<<<")
Pause 500
High Rst 'ready for tx
hspiout($bf) 'Read all 8 RTC registers in burst mode
hspiin(V_Sec,V_Min,V_Hour,V_Date,V_Month,V_Day,V_Year,V_RTCon)
Low Rst ' Reset RTC
SEROUT V_LCDPort,V_LCDData,(92,66,39,37,V_Date,"/")
SEROUT V_LCDPort,V_LCDData,(92,66,42,37,V_Month,"/")
SEROUT V_LCDPort,V_LCDData,(92,66,45,37,V_Year)
SEROUT V_LCDPort,V_LCDData,(92,66,39,38,V_Hour,":")
SEROUT V_LCDPort,V_LCDData,(92,66,42,38,V_Min,":")
SEROUT V_LCDPort,V_LCDData,(92,66,45,38,V_Sec)
Return
'************************************************************
DispReset:
'Add no scroll etc here
SEROUT V_LCDPort,V_LCDData,(92,66,32,32,"Date : / /")
SEROUT V_LCDPort,V_LCDData,(92,66,32,33,"Time : : :")
SEROUT V_LCDPort,V_LCDData,(92,66,32,34,"Sgnl :")
SEROUT V_LCDPort,V_LCDData,(92,66,32,35,"Sats :")
SEROUT V_LCDPort,V_LCDData,(92,66,32,36," ")
SEROUT V_LCDPort,V_LCDData,(92,66,32,37,"Date :")
SEROUT V_LCDPort,V_LCDData,(92,66,32,38,"Time :")
SEROUT V_LCDPort,V_LCDData,(92,66,32,39,"Stat :")
Return
'************************************************************