SPI interface with RTC DS3234
#1
Posted 14 July 2011 - 07:03 AM
Need helps on how to program and interface with this RTC DS3234 found in Sparkfun.
I have tried the connection wiring base on this reference link. The only things is that I don't connect the SQW pin on the breakout board. I suppose it is not use for RTC.
Also I have tried to start a new VB.net program to interface using the SPI but it always return 255 for each call.
Here is the datasheet for DS3234.
Please help.
#2
Posted 14 July 2011 - 08:01 AM
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#3
Posted 14 July 2011 - 08:28 AM
SQW stands for Square Wave.
I myself used an I²C realtime clock module, details @ http://wiki.netduino...k-Breakout.ashx
On that one the SQW pin isn't connected as well.
From your DS3234 Breakout, which pins are connected to the netduino, and to which pin on the netduino? I think it should be:
Gnd -> Netduino Gnd
VCC -> Netduino +3.3V
CLK -> Netduino Digital pin 13
MISO -> Netduino Digital pin 12
MOSI -> Netduino Digital pin 11
SS -> Netduino any GPIO pin (except for digital pin 4)
Yes, I am having the same connection. One thing I need to highlight is that I did not provide the battery during my testing.
I will download the sample code from your link and test it out.
(the code is for I2C, do you have any for SPI?)
Thanks.
#4
Posted 14 July 2011 - 08:37 AM
My sample code can't be used for SPI, you have to figure that part out yourself I only have the I²C-module since it was cheaper.Yes, I am having the same connection. One thing I need to highlight is that I did not provide the battery during my testing.
I will download the sample code from your link and test it out.
(the code is for I2C, do you have any for SPI?)
Thanks.
I think the battery is still required; the battery maintains the clock input and the 3.3V helps shifting the output. When I only get 255's from SPI I always toggle the bools in the SPI configuration on a trial/error base until it works
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#5
Posted 14 July 2011 - 08:46 AM
When I only get 255's from SPI I always toggle the bools in the SPI configuration on a trial/error base until it works
*** HORROR!!! HORROR!!! HORROR!!! ***
#6
Posted 14 July 2011 - 08:52 AM
really I've done that, with success The chip select bool I can read from the datasheet (should be False for the DS3234), but the clock states, no clue how to read that to be honest. Still a newb in many things here
*** HORROR!!! HORROR!!! HORROR!!! ***
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#7
Posted 14 July 2011 - 09:13 AM
#8
Posted 14 July 2011 - 09:17 AM
It's so trueStefan, read my signature...
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#9
Posted 14 July 2011 - 11:30 AM
One feels NetduBot could be in for a hard life - poor mite.
*** HORROR!!! HORROR!!! HORROR!!! ***
Regards,
Mark
To be or not to be = 0xFF
Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life
Follow @nevynuk on Twitter
#10
Posted 14 July 2011 - 11:35 AM
#11
Posted 14 July 2011 - 11:54 AM
Oh yea I know And I know trial/error is more or less a code design approach (and even then not the best), but I love it since it can be very educational! My Netdubot, if you looked closely, is built in modules, so if a module gets broken, it's easely replaceable. I know myself, some day that will be of much useMark, you're totally right!
Knowing that from Stefan, I guess the brand new creature he's building could be named as "Catduino". That's 'cos the nine lives the robot will have!
(Stefan, you *KNOW* I am kidding, true?...Don't be as my wife: touchy, touchy and touchy again...)
Cheers
But this is getting very very offtopic
Alex, how's the DS3234 going?
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#12
Posted 14 July 2011 - 03:07 PM
#13
Posted 15 July 2011 - 03:24 PM
No good. Still not able to get it working.
Probably getting the battery tomorrow and see if it really the battery.
But another thing is the address. Just wondering how to specify the start address for write and read for SPI programming.
managed to come across this sample codes on using this RTC.
I will need to get the correct battery and test it out again.
#14
Posted 30 September 2011 - 07:23 PM
Rusko
#15
Posted 01 October 2011 - 04:14 AM
Could you post the code?I'm facing the same problems... any news?
Thanks!
#16
Posted 01 October 2011 - 06:44 AM
using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; using System.Text; namespace RTC { public class Program { public static void Main() { string res; byte[] WriteBuffer = new byte[2]; byte[] ReadBuffer = new byte[2]; int Retry = 0; SPI.Configuration RTC1 = new SPI.Configuration( Pins.GPIO_PIN_D10, false, 0, 0, true, true, 1000, SPI_Devices.SPI1); SPI SPIbus = new SPI(RTC1); SPIbus.Config = RTC1; // Init Config: 60 = disable Oscillator and Battery SQ wave @1hz, temp compensation, Alarms disabled WriteAndCheck(SPIbus, 0x0E, 0x60); // Write Today Date & Time WriteAndCheck(SPIbus, 0x06, 0x11); // 2011 (year) WriteAndCheck(SPIbus, 0x05, 0x10); // 10 (month:October) WriteAndCheck(SPIbus, 0x04, 0x01); // 1 (day) WriteAndCheck(SPIbus, 0x03, 0x06); // 6 (Saturday ?) WriteAndCheck(SPIbus, 0x02, 0x08); // 8 (hours) WriteAndCheck(SPIbus, 0x01, 0x24); // 24 (minutes) WriteAndCheck(SPIbus, 0x00, 0x00); // 00 (seconds) do { res = ""; Retry = -7; // not counting the first read :-) for (byte d = 0; d < 7; d++) { // read addresses 0x00 to 0x06 until I get someting good (< 0xF0) do { WriteBuffer[0] = d; WriteBuffer[1] = 0; SPIbus.WriteRead(WriteBuffer, ReadBuffer); Thread.Sleep(10); Retry++; } while (ReadBuffer[1] > 0xF0); res = ReadBuffer[1].ToString("x") + ":" + res; } // Dump Debug.Print("20" + res + " - Retry = " + Retry.ToString()); Thread.Sleep(500); } while (true); } public static void WriteAndCheck(SPI device, byte Addr, byte Val) { byte[] writeBuffer = new byte[2]; byte[] readBuffer = new byte[2]; // Write at the given address until I read back the same value do { writeBuffer[0] = (byte)(Addr + 0x80); writeBuffer[1] = Val; device.Write(writeBuffer); Thread.Sleep(10); writeBuffer[0] = Addr; writeBuffer[1] = 0; device.WriteRead(writeBuffer, readBuffer); Thread.Sleep(10); } while (readBuffer[1] != Val); } } }
Now it's "almost" working... sometimes it took many retry to correctly read the date, sometimes not... why?!?! Many thanks!
EDIT: I forgot to say I'm using FW 4.2 RC1...
Rusko
#17
Posted 01 October 2011 - 07:54 AM
#18
Posted 01 October 2011 - 09:09 AM
Sorry for jumping in here - just interested in why you are writing out two bytes to the SPI interface when you read the contents of a register? Should the buffers be 1 byte long at this point? That's the way I interpret the timing diagram at the bottom of page 18 of the data sheet.
public static void WriteAndCheck(SPI device, byte Addr, byte Val) { byte[] writeBuffer = new byte[2]; byte[] readBuffer = new byte[2]; // Write at the given address until I read back the same value do { writeBuffer[0] = (byte)(Addr + 0x80); writeBuffer[1] = Val; device.Write(writeBuffer); Thread.Sleep(10); writeBuffer[0] = Addr; writeBuffer[1] = 0; device.WriteRead(writeBuffer, readBuffer); Thread.Sleep(10); } while (readBuffer[1] != Val); } }
Regards,
Mark
To be or not to be = 0xFF
Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life
Follow @nevynuk on Twitter
#19
Posted 01 October 2011 - 09:30 AM
AFAIK you cannot read without a write. I should write one byte (the address) and read one byte (a value)... I do both operations in one single shot: write address (and dummy read) and read value (with dummy write). Hope this is clear (and correct!).Sorry for jumping in here - just interested in why you are writing out two bytes to the SPI interface when you read the contents of a register? Should the buffers be 1 byte long at this point? That's the way I interpret the timing diagram at the bottom of page 18 of the data sheet.
BTW I'm writing a class to get/set a DateTime from the DS3234, I will post the code here as soon as I get something a little stable.
Rusko
#20
Posted 01 October 2011 - 03:03 PM
I have found the problem... bad contact on battery holder! Now is working without delay and retry! Many thanks to everybody!
AFAIK you cannot read without a write. I should write one byte (the address) and read one byte (a value)... I do both operations in one single shot: write address (and dummy read) and read value (with dummy write). Hope this is clear (and correct!).
BTW I'm writing a class to get/set a DateTime from the DS3234, I will post the code here as soon as I get something a little stable.
Take a look at this overloaded version of WriteRead...
public void WriteRead ( byte[] writeBuffer, int writeOffset, int writeCount, byte[] readBuffer, int readOffset, int readCount, int startReadOffset )
The key is startReadOffset, which allows you to tell the SPI device to wait until a number of bytes are written before starting to read. So, to read the time from DS3234, you could do this:
byte writeBuffer = new byte[] {0x00}; byte readBuffer[] = new byte[3]; device.WriteRead( writeBuffer, 0, 1, readBuffer 0, 3, 1 );
Hope this helps!
-Thomas
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users