Using SPI lib to integrate Arduino Due with DS3234 Deadon


#1

I’ve added a Deadon DS3234 RTC to DUE. I’m using the SPI header and driving SS (chip select) pin with D10.
The SPI is initialized:
import spi
spi0 = spi.Spi(chipSelPin, bits=spi.SPI_8_BITS, clock=1000000) # D10 is used as nss for SPI0
I chose the clock speed to be lower that the DS3234 max frequency (2 MHz when Vcc < 2.7 V).
On the DS3234, I’m writing to its Control Register (address 0x8E) a value of 0x18 to start the Oscillator and run a 8KHz clock on the INT/SQW pin as follows:
def wbyte(spiReg, txdata):
spiReg = bytes([spiReg])
txdata = bytes([txdata])
spi0.select()
hwtimers.sleep_micros(2)
try:
spi0.write(spiReg)
except Exception as e:
print(e, ‘Write register fail\r’)
hwtimers.sleep_micros(10)
dummyRd()
try:
spi0.write(txdata)
except Exception as e:
print(e, ‘Write txdata fail\r’)
hwtimers.sleep_micros(20)
dummyRd()
spi0.unselect()
return
This code runs without exception form a try block but the INT/SQW pin remains HIGH following the code execution.
I’ve inserted 2 - 20 micro sec delays between chip select and writes but continue to get the same response on INT/SQW.
Read operations to any register returns 0xFF. The read attempts is as follows:
def rbyte(spiReg, nbytes = 0x1):
spiReg = bytes([spiReg])
spi0.select()
hwtimers.sleep_micros(2)
try:
spi0.write(spiReg)
except Exception as e:
print(e, ‘Write address fail\r’)
hwtimers.sleep_micros(10)
try:
rxdata = spi0.read(nbytes)
except Exception as e:
print(e, 'Reading reg ‘, spiReg[0], ’ failed\r’)
hwtimers.sleep_micros(20)
spi0.unselect()
return rxdata
I did some crude troubleshooting with a LED connected to:
chip select (lights as expected)
SCLK (lights as expected during the chip select)
MOSI/MISO pins (dim glow during the R/W operations)
I looked through the zerynth docs and could not find clear instructions on the argument type needed for the spi0.write()/spi0.read() functions.
I’d appreciate so help on how to proceed.
Thanks.


#2

Hi Irfaun,

To better understand and test your code so I can replicate your issue, can you post me in a zip you project?
Thanks :wink:


#3

Hi Matteo,
See attached.spi_rtc.zip (63.4 KB)