View previous topic :: View next topic |
Author |
Message |
Flippy Guest
|
Questions about DS1305.c with PIC 18F4520 |
Posted: Fri Jul 06, 2007 6:24 am |
|
|
Hello everyone!
I am using PCWH Compiler 4.042.
I got a DS1305 connected to my PIC 18F4520 :
PIN C1: RTC_CS
PIN C3: SPI_SCK
PIN C4: SPI_MISO
PIN C5: SPI_MOSI
RTC:
Sermode is on Vcc (--> SPI).
I tried to included ds1305.c and trieg to get the RTC working, but untill now without success.
I just don't get data from the RTC.
What made me quite unsure is that the ds1305.c uses only 3 pins instead of 4.
ccsinfo.com/forum/viewtopic.php?t=29848&highlight=ds1305
Here it is said that Software-SPI is used, but I really can't figure out why (I thought it was 3-Wire because of the RTC_IO) and how it is working.
I checked the signals from the PIC, and they seem to be alright.
I am also using an AT25256 on the same Pins (C3-C5) and everything seems to works fine (I just had to redefine the Pins in the AT25256.c! But there are four pins used.).
I am trying to get the RTC working for 1,5 days now and I kinda looked through half of the internet but I just don't get it.
I hope you can help me, thank you! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 06, 2007 11:17 am |
|
|
Quote: | What made me quite unsure is that the ds1305.c uses only 3 pins instead of 4. |
The CCS driver expects the SDI and SDO pins on the DS1305 to be
connected together. You must add this connection to your hardware.
These two pins together are then connected to a single pin on the PIC,
which the CCS driver calls "RTC_IO". |
|
|
Flippy Guest
|
|
Posted: Mon Jul 09, 2007 12:03 am |
|
|
thanks a lot!
I also have to connect the SERMODE-Pin on the ds1305 to GND to activate the 3-Wire Interface, right ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 09, 2007 12:47 am |
|
|
That's correct. That's what the data sheet says. |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Mon Jul 09, 2007 2:07 am |
|
|
I've just finished getting my DS1305 to work with the CCS driver. I'm using 4-wire mode (SERMODE tied high) since I have several other 4-wire devices on the same bus. I modified the CCS code to split the RTC_IO into RTC_IN and RTC_OUT (while I was doing that I renamed the misleading RTC_RST to RTC_CE) *and* modified it to use hardware instead of software I/O.
The only problem I had was forgetting to use SPI mode 1 (or 3): Code: | setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_16); | (my system clock is 25MHz, hence DIV_16 to get it below the 2MHz specd in the DS1305 datasheet)
It's really nice of CCS to include all the code they do with their compiler, but IMO much of their "driver" code should be in the "examples" folder - it's just not well-written or flexible enough to be a proper reusable library. _________________ Andrew |
|
|
|