Keeping track of date and time

Started by David Sousa Mendes October 6, 2009
> ... how should the CS pin be configured?

OpenSPI will configure the /CS pin high. Its state before that should
be either untouched (since a processor Reset sets all pins to
InputTristate) or, if you like, you may set the pin to any state except
Low, which will likely cause the SPI device to interfere with code

Assuming you have an SPI device connected, with its /CS on pin 12, you
can test this easily:

Sub Main()
call sleep(1.0)

' call PutPin(12, bxOutputLow) ' will probably crash the machine
here, no flashing LED

call OpenSPI(1, 0, 12) ' pin 12 set high by Open

do ' flash LED
call PutPin(25, bxOutputLow)
call sleep(0.1)
call PutPin(25, bxOutputHigh)
call sleep(0.1)

End Sub

Thanx, Tom!
My next step is to try to configure the BX to communicate with max1302
via 3-wire protocol...
1 - What should I change on my pin configuration on the BX24 side?
2 - Should I still use OpenSPI and SPICmd commands?

David M.

> ... 1 - What should I change on my pin configuration on the BX24 side?
2 - Should I still use OpenSPI and SPICmd commands?

If, by "3-wire protocol" you mean SPI, if you are currently successful
with the max146, I see no reason to change anything except the data you
send to control the device, and the handling and interpretation of the
resulting data.


But on the max1302 side I only have the following pins for communication:
SCLK, I/O and CE
What should I connect to I/O? Both MISO and MOSI? Without external
components such as diodes or resistors?

David M.

> ... SCLK, I/O and CE...

Are we looking at the same part?

The Maxim Max1302 shows Din, Dout, SClk, and /CS.
No, sorry, the CORRECT part number is maxim's DS1302:

David M.
> ... DS1302...

Ah; you did say 3-wire and, you're right, that's not an SPI interface
device. You'd have better success, I think, using ShiftIn() and
ShiftOut() with it.

Somewhere up the thread, you were talking about using a DS1305, which is

Unfortunatly my DS1305 did not yet arrive and so I was trying to solve
my problem with a DS1302...
What is opinion?
1- Is it much hard work than with a SPI interface?
2 - DS1302 is LSB first whereas Shiftout command is MSB first... I would
need to do some bitwise operations, right?
3 - I would need to set the CE pin manually, right?

Thanks again for all your help
David M.

Yes, you'll need to control CE via PutPin(). On a quick read of the
DS1302 single-byte read/write specs, it looks like you need to raise CE,
then write a command byte then write a data byte for output to the
'1302, or write a command byte then read a data byte for input from the
'1302, then drop CE.

Reversing the bit order can be done in a simple loop, shifting one byte
value right while the other shifts left, or vice-versa. You might find
that, since you apparently need to loop through the byte anyway, it
might be easier to just output (or input) the bit using PutPin() then,
rather than wait for a complete reversed byte to use ShiftOut() or
ShiftIn(); if you do that you'll also need to generate the clock pulse
with a pair of PutPin(). The data rate would be slower that way but, if
you want to, you can speed it up later once you have something working.

I'll give it a try...
Meanwhile I came across the function FlipBits that, apparently reverses
the bit order automatically...
Have you heard about it?