Dear All.
I have a DS1305 connected to a Uno by SPI. The problem is that the DS1305 does not respond to any command given. I am running out of ideas to figure out the problem. Help is appreciated. Here is the code. Thanks.
#include <SPI.h>
#define DS1305_ADDRESS_OFFSET 80
#define SECONDS_REG 0x00
#define CONTROL_REG 0x0F
#include <SoftwareSerial.h>
#define rxPin 7
#define txPin 6
#define SSpin 10
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
void setup()
{
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
mySerial.begin(9600);
digitalWrite(SSpin, HIGH);
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV16);
SPI.setDataMode(SPI_MODE1);
writeRegister(CONTROL_REG,0x00);
unsigned int r = readRegister(CONTROL_REG);
mySerial.print("CONTROL = ");
mySerial.print(r,DEC);
writeRegister(SECONDS_REG,0x10);
}
void loop()
{
char s,min,h,d,m,y;
delay(1000);
unsigned int r = readRegister(CONTROL_REG);
mySerial.print("CONTROL = ");
mySerial.print(r,DEC);
r = readRegister(SECONDS_REG);
mySerial.print(":");
mySerial.println(r,DEC);
writeRegister(0x20,0x30);
r = readRegister(0x20);
mySerial.print("0x20 = ");
mySerial.println(r,HEX);
}
unsigned int readRegister(byte thisRegister)
{
byte inByte = 0;
unsigned int result = 0;
digitalWrite(SSpin, HIGH);
SPI.transfer(thisRegister);
result = SPI.transfer(0x00);
digitalWrite(SSpin, LOW);
return(result);
}
void writeRegister(byte thisRegister, char thisValue)
{
digitalWrite(SSpin, HIGH);
SPI.transfer(thisRegister+DS1305_ADDRESS_OFFSET);
SPI.transfer(thisValue);
digitalWrite(SSpin, LOW);
}