Author Topic: TROUBLE FINDING INFO ON USING DS1307  (Read 2721 times)

0 Members and 1 Guest are viewing this topic.

Offline neko efecktzTopic starter

  • Regular Contributor
  • *
  • Posts: 153
  • Country: au
TROUBLE FINDING INFO ON USING DS1307
« on: August 07, 2017, 11:39:44 pm »
THIS IS A RE-POST.
I first uploaded this post about 2 months ago but received no replies.
Had plenty of views but no replies.
I have been away for a month with my family and am now ready to tackle this problem again.

ORIGINAL POST FOLLOWS.


Good afternoon every one.
For a couple of weeks now I have been trying to download a workable code for PIC16F877A and LCD to set and display a DS1307 RTC.
I'm using PIC16F877A because that is what I have.

   Not working at it full time.
I am using MPLAB and am still basically a beginner.
A lot of code on line is written in micro C or some other language  called ASSY. Actually I know what ASSY is but I don't want to learn that as well as C.
I use MPLAB because it works with PicKit 3
I use Pickit 3 Because it works with MPLAB,
I use PIC's because they work with MPLAB and Pickit 3
   if you get the way I've drifted so far.    Quote Henry Blake (M*A*S*H)
I managed to find some code written in MPLAB C and looked like it might get me started.
I downloaded the code that included    i2c.h   RTC.h   &   RTC.C
I added my own LCD Display Code.

As can be seen i2c.h  has Processor:      PIC32MX
Does that mean this version is no good for PIC16F877A or just has some features that are not available in PIC16F877A but should still work.

Where can I find the file i2c_legacy

I'm not sure where I found the code.
I have tried to find it again to add links to this post but it eludes me for now.


i2c.h has
/*******************************************************************************
FileName:       i2c.h
Processor:      PIC32MX
Compiler:       Microchip MPLAB XC32 v1.00 or higher

Copyright © 2008-2009 released Microchip Technology Inc.  All rights
reserved.
*/
#ifndef _I2C_H_
#define _I2C_H_

#include <xc.h>
#include <GenericTypeDefs.h>

#ifndef _PLIB_DISABLE_LEGACY
#include <peripheral/legacy/i2c_legacy.h>  // Legacy definitions, do not use
#endif


RTC.h has
/*
 * File:   RTC.h
 * Author: B.BINDU
 * ST Number: 206017553
 * Created on 03 May 2013, 1:26 PM
 */
#include <xc.h>


RTC.C has
/*
 * File:   RTC.c
 * Author: Student Companion SA: www.studentcompanion.co.za
 * Real Time Clock Using DS1307 on I2C Bus
 * To simulate in Proteus, The I2C debugger must be connected on the I2C Bus.
 */
#include <xc.h>
#include "LCD_PORTS_V2.h"  // my own LCD Display code
#include "RTC.h"
#include <stdio.h>
#include <stdlib.h>
#include "i2c.h"

I am unable to find i2c_legacy.h online.
I have tried to find it in MPLABs download site but nothing obvious comes up.

If anyone can help me out It would be appreciated.

Thank you.
BILL.
 

Offline rcowboy78

  • Contributor
  • Posts: 43
  • Country: us
Re: TROUBLE FINDING INFO ON USING DS1307
« Reply #1 on: August 08, 2017, 12:00:38 am »
If you posted that as your first post 2 months ago I can see why no one has helped you. You obviously haven't done any leg work, and no one is going to help you if you haven't. First of all, your not going to be able to use a 32MX's code with a 16F, all of the pins are different and many other things such as timing, etc. 2nd, your going to have to use the XC8 compiler as I believe the 16F is a 8-bit chip.

Your going to have to start reading some data sheets, and start learning to code in C. Universities have courses on this stuff that last for months, and it's not going to be something that you pick up in a couple of nights.

Most of the LCD's data sheets comes with the setup code for initializing it so that you can get them up and running via parallel, SPI, I2C, or whatever it may be.

My other suggestion would be to also check out the microchip forum.

Sorry if i'm sounding harsh, I'm not trying to be.
« Last Edit: August 08, 2017, 12:02:45 am by rcowboy78 »
 

Offline neko efecktzTopic starter

  • Regular Contributor
  • *
  • Posts: 153
  • Country: au
Re: TROUBLE FINDING INFO ON USING DS1307
« Reply #2 on: August 08, 2017, 12:46:55 am »
rcowboy78
No offence taken.
I had already reconfigured the the code to use a PIC16F877A
Inputs, Outputs, LCD Display.
Getting a massive amount of errors that I think relate to the missing header file.

My main problem is that I am unable to find i2c_legacy.h online.
I have tried to find it in MPLABs download site but nothing obvious comes up.
I believe once I find this elusive file most of my problems will be solved.
That is if it works with a PIC16F877A
Apart from that I will as you say read as mush as i can on the subject and have another go at it from ground up.

Thankyou
BILL.


« Last Edit: August 08, 2017, 12:49:37 am by neko efecktz »
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2862
  • Country: 00
Re: TROUBLE FINDING INFO ON USING DS1307
« Reply #3 on: August 08, 2017, 01:20:04 am »
Go find I2C sample code that was actually written for the micro-controller and compiler you are using. Adapting some generic I2C code to work with the DS1307 with help of the datasheet will likely be much easier for a newbie than porting code between micro-controller families.

Offline JoeO

  • Frequent Contributor
  • **
  • Posts: 527
  • Country: us
  • I admit to being deplorable
Re: TROUBLE FINDING INFO ON USING DS1307
« Reply #4 on: August 08, 2017, 01:21:16 am »
Did you try to search for i2c_legacy.h ?

It was in the second line when I searched.

https://github.com/balazsracz/mr-misc/blob/master/pic32/includes/peripheral/legacy/i2c_legacy.h
The day Al Gore was born there were 7,000 polar bears on Earth.
Today, only 26,000 remain.
 

Offline rcowboy78

  • Contributor
  • Posts: 43
  • Country: us
Re: TROUBLE FINDING INFO ON USING DS1307
« Reply #5 on: August 08, 2017, 02:17:05 am »
Neko,

The other issue that I see that your going to have is that you are using 2 different devices on the same protocol. I am not an ECE or an embedded systems expert, I am sure this can be programmed around, but I would suggest using the LCD in parallel via either 8-bit mode, or 4 bit mode while your clock is ran on I2C. 2 devices on the same data lines are going to cause you problems unless they can be multiplexed or something. You can do as I suggested, or you can get another chip with 2 I2C ports. Your PIC16F877A only has 1. Might as well make it easier for yourself.

Maybe someone will correct me if I'm wrong about the above, as I don't do a ton of embedded stuff, but I've done enough to get myself in trouble.

Guess I need to correct myself here, looks like you can run multiple slaves on I2C. Found a good paper by Ti on it.

http://www.ti.com/lit/an/slva704/slva704.pdf
« Last Edit: August 08, 2017, 02:46:27 am by rcowboy78 »
 

Offline neko efecktzTopic starter

  • Regular Contributor
  • *
  • Posts: 153
  • Country: au
Re: TROUBLE FINDING INFO ON USING DS1307
« Reply #6 on: August 08, 2017, 04:54:30 am »
rcowboy78
I'm not sure how you came to the conclusion I was going to run the clock and LCD on the same data lines.
The LCD will be running from Port D while the clock is running on the I2c port of port C.
The LCD is running in 4 bit mode.

Joe0
I had found the https://github.com/balazsracz/mr-misc/blob/master/pic32/includes/peripheral/legacy/i2c_legacy.h you recomended I look at
It has a include to another file
#include <peripheral/int.h>

How many layers of includes can you use.

 alm
you recommended
Quote
Go find I2C sample code that was actually written for the micro-controller and compiler you are using. Adapting some generic I2C code to work with the DS1307 with help of the datasheet will likely be much easier for a newbie than porting code between micro-controller families.
This is where I started and got nowhere fast.
I spent hours trying to find something that looked like a complete code but there seems to be bits missing from that code supplied or missing header files etc.

When I first started out about a year ago I was able to, once guided in the right direction, create lcd driver and then I was able to do analog inputs etc.
The clock is not important for my current project but it would be nice to be able to build it into other future projects.

Google Chrome search engine is not selective enough
SEARCH FOR... ds1307 PIC16F877A
Usually gives me any clock chip used with any PIC programmed with any programmer in any language. MicroC, ASSY, even found a full working version? in HEX.
No idea where anything is connected. just code.
if i add MPLAB into the search field I wind up with a lot more rubbish to filter through.

I haven't given up on being able to get a clock working but was hoping to find a simple working code that I could adapt.

Thanks for your help and suggestions
 

Offline CJay

  • Super Contributor
  • ***
  • Posts: 4136
  • Country: gb
Re: TROUBLE FINDING INFO ON USING DS1307
« Reply #7 on: August 08, 2017, 10:21:33 am »
I have code, in C, written for 18F4550, should be fairly easy to change.

PM me
 

Offline neko efecktzTopic starter

  • Regular Contributor
  • *
  • Posts: 153
  • Country: au
Re: TROUBLE FINDING INFO ON USING DS1307
« Reply #8 on: August 08, 2017, 10:26:51 am »
CJay
Are you able to attach the code

Thankyou
BILL/
 

Offline CJay

  • Super Contributor
  • ***
  • Posts: 4136
  • Country: gb
Re: TROUBLE FINDING INFO ON USING DS1307
« Reply #9 on: August 08, 2017, 10:40:44 am »
CJay
Are you able to attach the code

Thankyou
BILL/

Ah, my bad, it's written for MPLABX/XC8 and is designed to drive a TM1638 to display the time held in the DS1307, it's proof of concept code (I.E. it sets up the DS1307 with a fixed time and then reads it before sending it to the display) so you'd need to add LCD routines, time setting routines and generally make it suitable for your needs but it does work.

Not really prepared to make it public (though anyone who asks could have a copy) as it's not something I want to have to support forever but if you'd like a copy i can PM it later?
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2862
  • Country: 00
Re: TROUBLE FINDING INFO ON USING DS1307
« Reply #10 on: August 08, 2017, 11:58:38 am »
alm
you recommended
Quote
Go find I2C sample code that was actually written for the micro-controller and compiler you are using. Adapting some generic I2C code to work with the DS1307 with help of the datasheet will likely be much easier for a newbie than porting code between micro-controller families.
This is where I started and got nowhere fast.
I spent hours trying to find something that looked like a complete code but there seems to be bits missing from that code supplied or missing header files etc.
Try to find code that was written for the same compiler and micro family that you are using. And I was suggesting finding sample code that does just the I2C master part. Something like this might work. Search terms: pic16 xc8 i2c sample code. The DS1307 part you might have to code yourself from the datasheet. This is in my opinion an absolute bare minimum skill for embedded development.

If that is too complicated, then maybe something easier like Arduino might be a better solution? That should provide more hand-holding and there will be more sample code available from the likes of Adafruit.

Offline rcowboy78

  • Contributor
  • Posts: 43
  • Country: us
Re: TROUBLE FINDING INFO ON USING DS1307
« Reply #11 on: August 08, 2017, 03:30:27 pm »
Quote
I'm not sure how you came to the conclusion I was going to run the clock and LCD on the same data lines.
The LCD will be running from Port D while the clock is running on the I2c port of port C.
The LCD is running in 4 bit mode.

Sorry, just from the way you wrote the OP it sounded like that was what you were going to do. You didn't mention anything about how you were trying to program the LCD, so I assumed thats what it was.

But you can to do both using I2C from the little bit of reading that I have done.

 

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: TROUBLE FINDING INFO ON USING DS1307
« Reply #12 on: August 08, 2017, 03:50:52 pm »
By the time you've got someone else's code working you could set up the PIC16F877A's I2C, and the DS1307's registers yourself.  :)
.  That took much longer than I thought it would.
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 11473
  • Country: ch
Re: TROUBLE FINDING INFO ON USING DS1307
« Reply #13 on: August 08, 2017, 10:58:48 pm »
FWIW, I'd ditch the DS1307 and use the DS3231 instead, unless cost (via official distributors) is a huge issue. It's far more accurate, and doesn't need external components.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf