|
|
View previous topic :: View next topic |
Author |
Message |
JamesW Guest
|
Has anyone managed to get a DS1305 working with SPI |
Posted: Mon Sep 26, 2005 11:15 am |
|
|
if so, can anyone give me few pointers please?
I am running on a 18F4525 at 20MHz, the chip select is on pin A5, the sermode pin on the DS1305 is at VCC.
(I know the SPI is working, as I have a MAX3110 on it that I have already got working).
Looking at the output data from the chip on a logic analyser it is doing absolutely nothing. (The write and read looks fine with the right number of clock signals etc.)
Theoretically If I write data to the 1st address in ram, and read from it using the routines below, I should be able to get something, but I get nothing. (The line just sits there at 5v)
I have got a 100K pull up on the SDO from the DS1305 as well, as I saw a post elsewhere that said it was an open collector output.
I have tried just these combinations of setup_spi just in case
setup_spi(SPI_MASTER | SPI_XMIT_L_TO_H | SPI_CLK_DIV_64);
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_64);
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_64);
I must be missing a fundemental point, but cannot work out what.
Any pointers would be very gratefully received, as I am tearing my hair out at the moment
Code is below
Cheers James
/* ------------------------------------------------------------------------- */
/* ROUTINE TO WRITE A BYTE TO THE DS1305 */
void write_ds1305_byte(BYTE cmd)
{
BYTE i;
spi_write(cmd);
}
/* ------------------------------------------------------------------------- */
/* ROUTINE TO WRITE A BYTE TO AN ADDRESS IN THE DS1305 */
void write_ds1305(BYTE cmd, BYTE data)
{
unsigned int temp;
output_high(DS1305_CS);
delay_us(10);
write_ds1305_byte(cmd);
write_ds1305_byte(data);
delay_us(10);
output_low(DS1305_CS);
}
/* ------------------------------------------------------------------------- */
/* ROUTINE TO READ A BYTE FROM A DS1305 */
BYTE read_ds1305(BYTE cmd)
{
BYTE i,data;
output_high(DS1305_CS);
delay_us(100);
spi_write(cmd);
delay_us(5);
data = spi_read(0);
delay_us(10);
output_low(DS1305_CS);
return(data);
}
/* ------------------------------------------------------------------------- */
void rtc_write_nvr(BYTE address, BYTE data)
{ //valid address: 0x00 to 0x5F
write_ds1305(address | 0xa0, data);
}
/* ------------------------------------------------------------------------- */
BYTE rtc_read_nvr(BYTE address)
{
return(read_ds1305(address | 0x20));
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 26, 2005 12:29 pm |
|
|
With respect to the hardware:
1. Do you have Vccif connected to Vcc1 (both at +5v) ?
2. Do you have a 3v lithium battery connected to Vbat ?
3. Do you have a 32.768 KHz crystal connected to X1 and X2 ?
4. Do you have Vcc2 connected to Ground ?
Also, I don't see an init routine in your code, that sets up the
control register to remove Write Protect and to enable the oscillator. |
|
|
JamesW Guest
|
|
Posted: Fri Sep 30, 2005 8:33 am |
|
|
ahh - thanks for that, I didn't notice the read/write flag in the datasheet.
I had it working, but now it's stopped again! Damn hardware!
Cheers
James |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|