Reply by David Sousa Mendes November 13, 20092009-11-13
Hello fellows
The problem was finnally solved as soon as I called Maxim's support line.
According to their Typical Operation Circuit, I had my supply connected
to Vcc2 pin...
Apparently, when you have a single supply, this should be connected to
Vcc1 and not to Vcc2 as they suggest on their scheme...
When I changed the wires, all started to work properly!
Thanks again for all your help!!
Best regards
David M.

Reply by rosa...@aol.com November 10, 20092009-11-10
Hi,

Suggestion
Do a print of the command data to see if your are sending command a good command.
Set the clock low before execute the CE high per DS1302 define instruction.
I know that you are setting it after the shiftin instruction but when you start the program the setting maybe unknown.
Add a small delay after the shiftout instruction.
See if it help with your problem.

rosarite

-----Original Message-----
From: David Sousa Mendes
To: b...
Sent: Tue, Nov 10, 2009 3:38 pm
Subject: [BasicX] Keeping track of date and time

I tried want you suggested: instead of MISO and MOSI pins, I'm only

using one pin connected to IO pin of DS1302...

But the result is the same: "ctrl_reg: 255"



Reply by David Sousa Mendes November 10, 20092009-11-10
Do you think I should configure the IO pin as bxInputTristate using Putpin?

Reply by David Sousa Mendes November 10, 20092009-11-10
I tried want you suggested: instead of MISO and MOSI pins, I'm only
using one pin connected to IO pin of DS1302...
But the result is the same: "ctrl_reg: 255"

Reply by Tom Becker November 10, 20092009-11-10
> ... both pins are connected to IO pin of DS1302...

Then the output pin will hold the input pin low, won't it? Try
disconnecting one of the pins and use the same pin for input and output.
Tom
Reply by Tom Becker November 10, 20092009-11-10
You can't be far from success. Here is a Cubloc implementation that is
close to Basic-X code:

http://www.cubloc.com/download/etc/app_ds1302.pdf
Tom
Reply by David Sousa Mendes November 10, 20092009-11-10
yes, both pins are connected to IO pin of DS1302
Reply by Tom Becker November 10, 20092009-11-10
> public const MISO as byte
> public const MOSI as byte

Are these two pins both connected to the DS1302 I/O pin?
Tom
Reply by David Sousa Mendes November 10, 20092009-11-10
Hello Tom,
I tried the code that you suggested but with no results...
At the moment I'm just trying to read a register where the first 7 bits
are forced to zero, but my code delivers the decimal value of 255...
Below, I'm sending you the code... May be you have an idea what might I
be doing wrong...
Again, thanks for your help...

Option Explicit
public const SCLK as byte
public const MISO as byte
public const MOSI as byte
public const CE as byte

Public Const SecReg As Byte = bx0000_0000 'Seconds Register (#0)
Public Const MinReg As Byte = bx0000_0010 'Minutes Register (#1)
Public Const HrsReg As Byte = bx0000_0100 'Hours Register (#2)
Public Const DayReg As Byte = bx0000_0110 'Day-Of-Month Register (#3)
Public Const DateReg As Byte = bx0000_1000 'Month Register (#4)
Public Const MonReg As Byte = bx0000_1010 'Day of Week Register (#5)
Public Const YrReg As Byte = bx0000_1100 'Year Register (#6)
Public Const CtrlReg As Byte = bx0000_1110 'Control Register (#7)
Public Const TchgReg As Byte = bx0001_0000 'Trickle Charge Register (#8)

Public Const ClockReg as Byte = bx1000_0000
Public Const RAMReg as Byte = bx1100_0000
Public Const ReadReg as Byte = bx1000_0001
Public Const WriteReg as Byte = bx1000_0000

Public Const nb_of_bits as byte=8
Public command as byte
Public received_byte as byte
Public Sub Main()
call delay (1.0) ' para set the Xtal stable

'Reads the control
register___________________________________________________________________________________
do
command=ClockReg OR CtrlReg OR ReadReg
command = FlipBits (command) ' because DS1302 is LSB first
call putpin(CE,bxOutputHigh) ' CE must be asserted high during
communication
Call ShiftOut(MOSI, SCLK, nb_of_bits, command)
received_byte =Shiftin(MISO, SCLK, nb_of_bits)
Call PutPin(SCLK, bxOutputLow) ' sets the SCLK pin to low after
communication
call putpin(CE,bxOutputLow) ' CE must be asserted low after
communication
received_byte=FlipBits(received_byte)
debug.print "ctrl_reg: " ; CStr(received_byte)
call delay (1.0)
loop

End Sub

Reply by Tom Becker November 5, 20092009-11-05
> ... FlipBits...

Perfect. I've never used it, but that's what you need if you use
ShiftIn/Out.
Tom