jboyton:
I think that would work.I would choose to do something like this:
void DS3234::_read_raw (void)
{
uint8_t x = 7;
digitalWrite (_ss_pin, LOW);
_spi_transfer(0); // time registers: addr 0-6
while (x--) {
*(_buffer + x) = _spi_transfer(0);
}
digitalWrite(_ss_pin, HIGH);
}
OK, I tried something: I modified your test sketch to use my library for reads. Sure enough, it's got the problem. Here's the output from the test sketch using the library for read:
[b]
RTC glitch test using DS3234 Library
01:00
00:00
01:00
00:00
00:00
01:00
00:00
00:00
00:00
01:00
00:00
01:00
00:00
[/b]
Now with the define changed to use the software direct read you did:
[b]
RTC glitch test using Burst read
01:00
01:00
01:00
01:00
01:00
01:00
01:00
01:00
01:00
01:00
01:00
01:00[/b]
Here is the test sketch itself if you want to try it:
#include <DS3234.h>
// DS3234 pin connections
#define __GND 99 // solid gnd
#define __VCC 13
#define __SQW 12
#define __SCK 11
#define __MISO 10
#define __MOSI 9
#define __SS 8
// original defines from the test sketch
#define CLK_PIN 11
#define MISO_PIN 10
#define MOSI_PIN 9
#define SS_PIN 8
#define USE_DRIVER // comment this out to use direct read
uint8_t hour, mins, secs, month, day, dow;
uint16_t year;
char buffer[16];
uint8_t bcd2dec (uint8_t bcd)
{
return (bcd / 16 * 10) + (bcd % 16);
}
void displayMMSS (uint8_t mins, uint8_t secs)
{
sprintf (buffer, "%02u:%02u\n", mins, secs);
Serial.print (buffer);
}
// transfer one byte via SPI Mode 3
uint8_t spi_transfer (uint8_t data)
{
uint8_t bits;
bits = 8;
while (bits--) {
digitalWrite (CLK_PIN, LOW);
digitalWrite (MOSI_PIN, data & _BV (bits) ? HIGH : LOW);
digitalWrite (CLK_PIN, HIGH);
digitalRead (MISO_PIN) ? data |= _BV (bits) : data &= ~_BV (bits);
}
return data;
}
uint8_t spi_command (uint8_t cmd, uint8_t data)
{
digitalWrite (SS_PIN, LOW);
spi_transfer (cmd);
cmd = spi_transfer (data);
digitalWrite (SS_PIN, HIGH);
return cmd;
}
void burst (uint8_t *secs, uint8_t *mins)
{
digitalWrite (SS_PIN, LOW);
spi_transfer (0x00);
*secs = spi_transfer (0x00);
*mins = spi_transfer (0x00);
digitalWrite (SS_PIN, HIGH);
}
int main (void)
{
init();
Serial.begin (115200);
digitalWrite (__GND, LOW);
digitalWrite (__VCC, HIGH);
pinMode (__GND, OUTPUT); // enable gnd first
pinMode (__VCC, OUTPUT); // turn on power for clock
pinMode (__SQW, INPUT_PULLUP); // no bus contention with SQW pin
RTC.init (__SCK, __MISO, __MOSI, __SS); // init the RTC
Serial.print ("\nRTC glitch test using");
#ifdef USE_DRIVER
Serial.print (" DS3234 Library\n\n");
#else
Serial.print (" Burst read\n\n");
#endif
while (1) {
spi_command (0x80, 0x59); // write seconds = 59
spi_command (0x81, 0x00); // write minutes = 00
while (1) {
#ifdef USE_DRIVER
dow = RTC.getTime (hour, mins, secs, month, day, year);
#else
burst (&secs, &mins);
mins = bcd2dec (mins); // raw read is in BCD so convert it
secs = bcd2dec (secs);
#endif
if ((secs == 0x00) || (mins == 0x01)) { // if rollover
displayMMSS (mins, secs);
break;
}
}
}
}
Lastly, attached is a ZIP file of the DS3234 library. It's been updated a bit from the one on Github, and you should use the same one as I did for testing...
ds3234.zip (4.4 KB)