CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Test code to test ds1305.c

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
C0J



Joined: 05 Nov 2008
Posts: 25

View user's profile Send private message

Test code to test ds1305.c
PostPosted: Sat Jun 13, 2009 12:54 pm     Reply with quote

Hi,

Anyone mind providing a test code to test out the ds1305.c in c:\program files\picc\drivers

Thanks,
CJ
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jun 13, 2009 11:40 pm     Reply with quote

The Ex_rtclk.c program uses the ds302.c driver. That driver has the
same function interface as the ds1305.c driver. You should be able to
just change the #include file in the following program and make it work.
Here's the file location:
Quote:
c:\program files\picc\examples\ex_rtclk.c

Notes:
The "RTC_RST" on the PIC should be connected to the CE pin on the
ds1305.

The SDI and SDO pins on the ds1305 should be connected together
and should connect to the RTC_IO pin on the PIC.

RTC_SCLK on the PIC should connect to SCLK on the ds1305.

The SERMODE pin on the ds1305 should be connected to ground.

See the ds1305 data sheet for the battery and crystal connections.
C0J



Joined: 05 Nov 2008
Posts: 25

View user's profile Send private message

PostPosted: Sun Jun 14, 2009 10:03 am     Reply with quote

Thanks PCM
krugger



Joined: 12 Jul 2011
Posts: 18
Location: El Salvador

View user's profile Send private message

Using 4 wire-SPI between PIC16F1827 and DS1305
PostPosted: Thu Oct 06, 2011 5:34 pm     Reply with quote

Hi,

I was wondering if it's possible to connect DS1305 RTC to PIC16F1827 using a 4 wire-SPI. The DS1305 datasheet it's says:

"The serial peripheral interface (SPI) is a synchronous bus for address and data transfer, and is used when interfacing with the SPI bus on specific Motorola microcontrollers such as the 68HC05C4 and the 68HC11A8."

but I don't find any inconvenience in using another microcontroller instead of Motorola's ones, given that we use the same kind of signals for SCK, and CE.

Am I correct, haven't I considered something or am I simply asking something foolish?

Thank you in advance.

Pablo
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 06, 2011 5:58 pm     Reply with quote

Yes, you can write a CCS driver for 4-wire hardware SPI for the ds1305.
However, note that the CE signal is high-true on the ds1305. Also note
that it must use SPI mode 1 or 3. These items don't present a problem,
I'm just saying to be aware of them.
krugger



Joined: 12 Jul 2011
Posts: 18
Location: El Salvador

View user's profile Send private message

PostPosted: Thu Oct 06, 2011 6:11 pm     Reply with quote

Thank you PCM,

When you say SPI mode 1 or 3 you are referring to these definitions, arent't you?

Code:
#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)


I don't understand exactly why do they have to be 1 or 3.

Furthermore, I have included this line in my main .c file:

Code:
#USE SPI (MASTER, SPI1, MODE=0, BITS=8, STREAM=RTC, MSB_FIRST, CLOCK_HIGH=1, CLOCK_LOW=1)


I'm using 4 Mhz for my PIC and I am a bit concerned about the maximum frequency for RTC_SCK (2 Mhz), that's why I added the CLOCK_HIGH and CLOCK_LOW options and set them to its minimum value. Is this correct? (I'd rather use SPI_CLK_DIV_4 but I guess that option is only to be used with setup_spi()...

I have also added some methods to DS1305.c driver to communicate with it using HW SPI pre-built functions.

Hope it works. I'll post it if this happens.

Pablo
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 06, 2011 6:33 pm     Reply with quote

Quote:
When you say SPI mode 1 or 3 you are referring to these definitions, aren't you?

Yes, and also the actual physical hardware inside the ds1305 that
determines the SPI mode.

Quote:
I don't understand exactly why do they have to be 1 or 3.

Because it says on the first page of the ds1305 data sheet exactly
what SPI modes are supported (left side of the page, 4th item down):
Quote:

Supports Motorola SPI (Serial Peripheral Interface)
Modes 1 and 3 or Standard 3-Wire Interface

http://pdfserv.maxim-ic.com/en/ds/DS1305.pdf


Quote:
Furthermore, I have included this line in my main .c file:

#USE SPI (MASTER, SPI1, MODE=0, BITS=8, STREAM=RTC, MSB_FIRST, CLOCK_HIGH=1, CLOCK_LOW=1)

The mode is wrong, and you don't need the two clock parameters.
It's easier to specify the maximum desired SCLK frequency by using the
BAUD parameter instead. See the CCS manual in the #use spi() section.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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