Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Spurious SCl transition detected in proteus: RTC DS1307 and PIC 18F4520

Status
Not open for further replies.

Nagesh29

Junior Member level 2
Junior Member level 2
Joined
Oct 9, 2013
Messages
22
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Activity points
129
Hie..

I am using pic 18f4520 microcontroller and DS1307 RTC and MPLAB C18 compiler.
When I try to simulate the code in proteus I get spurious scl transition detected..
My RTC terminal shows the same values I have written in the code but with no change.

Also, when I tried with the same logic in micro c, it works perfectly fine.
I have used the below function to wait I2C bus is micro c:
while(!(I2C1_Is_Idle()));

I have not found similar function in C18 I2C library.


Here is entire my code::

Code:
#include <p18f4520.h>
#include <i2c.h>
#include <Delays.h>
char minutes,seconds,day,hrs,date,month,year;

void main()
{
OpenI2C(MASTER,SLEW_OFF); 
StartI2C();
WriteI2C(0xD0);
WriteI2C(0x00);
WriteI2C(0x80);

WriteI2C(0x10); //minutes
WriteI2C(0x10); // hours
WriteI2C(0x2); //day
WriteI2C(0x22); //date
WriteI2C(0x4); //month
WriteI2C(0x13); //year
StopI2C();

//Start Rtc Oscillator 
StartI2C();
WriteI2C(0xD0); //address of rtc device
WriteI2C(0x00); //0th memory location
WriteI2C(0x00); // EOSC-bar: start osciallator of rtc
Delay1KTCYx(25);

while(1)
{

// Read RTC Data
StartI2C();
WriteI2C(0xD0);//address of rtc device
WriteI2C(0x00);//0th memory location

RestartI2C();
WriteI2C(0xD1); //address of rtc device 

seconds = ReadI2C();
AckI2C();
minutes = ReadI2C();
AckI2C();
hrs =ReadI2C();
AckI2C();
day =ReadI2C();
AckI2C();
date=ReadI2C();
AckI2C();
year=ReadI2C();
NotAckI2C();
StopI2C();

//while ( !DataRdyI2C() );
seconds  =  ((seconds & 0xF0) >> 4)*10 + (seconds & 0x0F);  // Transform seconds
minutes  =  ((minutes & 0xF0) >> 4)*10 + (minutes & 0x0F);  // Transform months
hrs  =  ((hrs & 0xF0) >> 4)*10 + (hrs & 0x0F);  // Transform seconds
day  =  ((day & 0xF0) >> 4)*10 + (day & 0x0F);  // Transform months
date  =  ((seconds & 0xF0) >> 4)*10 + (date & 0x0F);
month  =  ((seconds & 0xF0) >> 4)*10 + (month & 0x0F);
year  =  ((seconds & 0xF0) >> 4)*10 + (year & 0x0F);

Delay1KTCYx(25);
while(1);
}
}
https://obrazki.elektroda.pl/5995338100_1381310071.png
https://obrazki.elektroda.pl/4358774900_1381310071.png

Plz help me with this..
Thanx.!
 
Last edited by a moderator:

Did you apply pull ups on clock and data line ?
 

@Venkadesh:

Plz find above link for Proteus file.
 

Hi i mean proteus project file compress it with hex file and pot here with manage attachments link below.....................
 

Resistors should be 4.7k digital type in Proteus and You should connect a 3V battery to RTC. Also you should connect a crystal of 32.768 KHz to the RTC.
 

@Jayanth

The same Proteus simulation works perfectly fine when I am using hex file of my micro c code..
I think the problem is with mplab code..
 

Zip and post MPLAB project files and Proteus file for quick solution. I don't have time to create new projects for every code posted asking help.

remove this second

Code C - [expand]
1
while(1);

at the end of code.

The code stucks execution stucks at 2nd while(1) loop and never comes out.
 

PFA..
Removed while(1) ..
Does not work for me..
 

Attachments

  • I2C.rar
    16.7 KB · Views: 159

I can't help you. You have not posted the mplabRTC.c file. When you make up your mind to properly post all the project files then only expect help.
 

sorry Jayant..
There was little bit confusion about the file..
 

Attachments

  • I2C.rar
    17.5 KB · Views: 115

Hi that is due to missing the start of transmission signal, The data shd be appear after the S in the debugger without it, it considers as noise... there must be a delay between start and stop I2C, so try some delay between stop and start I2C if still problem persists check the function of I2C start....

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
WriteI2C(0x25);         // write 25 to date word (REG4)
    WriteI2C(0x09);         // write 9 (September) to month word (REG5)
    WriteI2C(0x08);         // write 08 to year word (REG6)
    StopI2C();              // issue stop signal
    
    Delay10KTCYx(25);
 
    StartI2C();             // issue start signal
    WriteI2C(0xD0);         // address DS1307
    WriteI2C(0);            // start from word at address 0
    WriteI2C(0);            // write 0 to REG0 (enable counting + 0 sec)



- - - Updated - - -

untitled.JPG the noise indicates no s
 

Thank you very much for your response..
I have added some delay between start and stop conditions.
Now, my rtc timer works fine but resets after 2 seconds.
Also, If I have disabled my watchdog timer I2C timer works good but I2C debugger is not showing any value there.
Plz Help !
 

@jayant..
PFA for udated code..
Thanx.
 

Attachments

  • I2C.rar
    16.3 KB · Views: 131

Why are you including p18f4520.h instead of p18f452.h?

Remove this line


Code C - [expand]
1
while ( !DataRdyI2C() );



Put these inside while(1) loop. Why did you modify those codes?


Code C - [expand]
1
2
3
4
5
6
7
seconds = ((seconds & 0xF0) >> 4)*10 + (seconds & 0x0F); // Transform seconds
minutes = ((minutes & 0xF0) >> 4)*10 + (minutes & 0x0F); // Transform months
hrs = ((hrs & 0xF0) >> 4)*10 + (hrs & 0x0F); // Transform seconds
day = ((day & 0xF0) >> 4)*10 + (day & 0x0F); // Transform months
date = ((seconds & 0xF0) >> 4)*10 + (date & 0x0F);
month = ((seconds & 0xF0) >> 4)*10 + (month & 0x0F);
year = ((seconds & 0xF0) >> 4)*10 + (year & 0x0F);

 

Thanx Jayant.
Removed while ( !DataRdyI2C() );
Transformation functions are already in main a while(1) loop.
Should I use another while(1) loop for those functions only?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top