View previous topic :: View next topic |
Author |
Message |
guest Guest
|
ds1302 interface with PIC!! |
Posted: Sat Nov 05, 2005 8:24 am |
|
|
Hi everyone!
i want to interface the RTC chip DS1302 to PIC16f877. i know that the drivers for this chip are available in the C compiler, but i need some help with the connections between PIC and DS1302. if any one has any idea than it would be a great help!
Thanks in advance |
|
|
VanHauser
Joined: 03 Oct 2005 Posts: 88 Location: Ploiesti, Romania
|
|
Posted: Sat Nov 05, 2005 9:05 am |
|
|
The DS1302 uses the I2C protocol in slow mode. Connect the SCL and SDA pins of the RTC to the PIC's C3 (SCL) and C4 (SDA) pins respectively. These two lines need to be pulled up to 5V by a 2K resistor each. Add the folowing line at the beginning of your code to enable the hardware I2C:
Code: | #use i2c(master, sda=PIN_C4, scl=PIN_C3, slow, force_hw) |
Don't forget the ds1302_init() function. The DS1302 datasheet might also help a lot. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Nov 05, 2005 11:12 am |
|
|
Quote: | The DS1302 uses the I2C protocol in slow mode. |
No. It uses the "3-wire" interface, which is similar to SPI, but it has
a bi-directional i/o pin. See the data sheet:
http://pdfserv.maxim-ic.com/en/ds/DS1302.pdf
Quote: |
I need some help with the connections between PIC and DS1302.
If any one has any idea than it would be a great help!
|
Look near the start of the CCS driver file, DS1302.c.
It gives some suggested pins that you can use.
You can use those pins, or re-define them to some other pins.
Code: | #define RTC_SCLK PIN_B1
#define RTC_IO PIN_B3
#define RTC_RST PIN_B2 |
|
|
|
hisham.i
Joined: 22 Aug 2010 Posts: 43
|
|
Posted: Mon Mar 21, 2011 2:46 pm |
|
|
Why DS1302 has a driver in ccs?, i thought that i can take data in and out like max7219, but in max7219 there is no driver. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 21, 2011 3:35 pm |
|
|
Quote: | but in max7219 there is no driver.
|
A "driver" is a software program that provides an easy-to-use software
interface to the hardware communications interface on a chip.
And yes, the max7219 requires a driver. Here is an example:
http://www.ccsinfo.com/forum/viewtopic.php?t=43621 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Mar 21, 2011 3:52 pm |
|
|
and, CCS, provides _a few_ sample drivers to talk to common chips, to help you write your own. The old DS1302, is a very common chip, hence there is a supplied example. For 99% of chips though, you need to write your own (or search and see if somebody else may have done one already).
Best Wishes |
|
|
|