Maker Pro
Maker Pro

Reg:- RTC using I2c

Respected Sir/Madam

I am trying to interface the DS1302 rtc chip to the
Aduc841 microconverter through i2c communication.The Aduc841 is
configured in i2c Master Mode.The transmission occurs correctly and it
is checked only in the simulation mode alone.While receiving the data
the SDA line remains high and data received is 0xFF.

The RTC registers should be read and to be displayed in the LCD.

Operatons Tried:

The seconds register is continuously read .

The write protect Bit is cleared.

eg:

MODE STATUS ADDRESS DATA

Master Transmit 0x80 24. (. stands for
ACK)

Master Receive 0x81 FF! (! stands for
NACK)

This is the result given in simulation. So kindly give me the
suggestions and tips to rectify the problem.

The reply is expected as soon as possible.

Regards
Alagu Sakthi
 
Respected Sir

Thanks for ur reply.As per your direction i have checked the address
and i am writing only to the seconds register.
Its address is 0x80 for writing and 0x81 for reading and no slave ID
for ds 1302 is given in the data sheet.
Please give me the steps to trouble shoot it.
Regards
Alagu Sakthi.
 
P

Pooh Bear

Respected Sir

Thanks for ur reply.As per your direction i have checked the address
and i am writing only to the seconds register.
Its address is 0x80 for writing and 0x81 for reading and no slave ID
for ds 1302 is given in the data sheet.

Are you confident about the proper operation of your I2C interface ? For
example have you used it with another simple peripheral ?

I don't see you sending a command byte ( see page 6 of the data sheet ).

Graham
 
Sir
I am tring the i2c between two Aduc841 microconverter.
The analog devices application note uc001 explains the i2c between the
same.

The UART functions are omitted and only the transceiving function is
written
for both slave and master and are fused seperately in two eval boards.

My code structure is

main
{
initialisation
set data(xxxx);
while(1)
{
getdata();
}
}
set data(xxxx)
{
write(0x80,xxxx); //80(adress) and xxxx data.
}


write(addr,data)
{
start();
senddata(addr);
senddata(data);
stop();
}

start()
{
when clk is high sda is puled low;
}

senddata(xxxx)
{
in this func the byte is send bit by bit with MSB first.
getack(); // ack given in s/w.

}

stop()
{
when clk is high sda is puled high;
}

getdata()
{
sec = read(0x81);
}

char read(0x81)
{
Startt();
SendData(0x81);
Receive_Byte();
Stop_Bit();
return(readdata);
}

receive_byte()
{
all the 8 bits received from MDI is stored temporarily in read data
variable and returned.
}


this code is for the master mode only.


|||y for the slave mode the interrupt polling is done and no output is
obtained. kindly give me the suggestions.


regards
Alagu.
 
P

Pooh Bear

Sir
I am tring the i2c between two Aduc841 microconverter.
The analog devices application note uc001 explains the i2c between the
same.

The UART functions are omitted and only the transceiving function is
written
for both slave and master and are fused seperately in two eval boards.

My code structure is

main
{
initialisation
set data(xxxx);
while(1)
{
getdata();
}
}
set data(xxxx)
{
write(0x80,xxxx); //80(adress) and xxxx data.
}

write(addr,data)
{
start();
senddata(addr);
senddata(data);
stop();
}

start()
{
when clk is high sda is puled low;
}

senddata(xxxx)
{
in this func the byte is send bit by bit with MSB first.
getack(); // ack given in s/w.

}

stop()
{
when clk is high sda is puled high;
}

getdata()
{
sec = read(0x81);
}

char read(0x81)
{
Startt();
SendData(0x81);
Receive_Byte();
Stop_Bit();
return(readdata);
}

receive_byte()
{
all the 8 bits received from MDI is stored temporarily in read data
variable and returned.
}

this code is for the master mode only.

|||y for the slave mode the interrupt polling is done and no output is
obtained. kindly give me the suggestions.

You must be using a 'library routine' for your write procedure I assume ?

It seems to me that you are not initiating the data transfer corrctly as I
understand it.

You need to send the 'command byte' without any data first to tell the
device how you want it to respond.

" COMMAND BYTE
Figure 4 shows the command byte. A command byte initiates each data
transfer. The MSB (bit 7) must be a logic
1. If it is 0, writes to the DS1302 will be disabled. Bit 6 specifies
clock/calendar data if logic 0 or RAM data if logic 1.
Bits 1 to 5 specify the designated registers to be input or output, and
the LSB (bit 0) specifies a write operation
(input) if logic 0 or read operation (output) if logic 1. The command byte
is always input starting with the LSB (bit 0). "

from page 6 of the data sheet.

Graham
 
P

Pooh Bear

Pooh said:
You must be using a 'library routine' for your write procedure I assume ?

It seems to me that you are not initiating the data transfer corrctly as I
understand it.

You need to send the 'command byte' without any data first to tell the
device how you want it to respond.

" COMMAND BYTE
Figure 4 shows the command byte. A command byte initiates each data
transfer. The MSB (bit 7) must be a logic
1. If it is 0, writes to the DS1302 will be disabled. Bit 6 specifies
clock/calendar data if logic 0 or RAM data if logic 1.
Bits 1 to 5 specify the designated registers to be input or output, and
the LSB (bit 0) specifies a write operation
(input) if logic 0 or read operation (output) if logic 1. The command byte
is always input starting with the LSB (bit 0). "

from page 6 of the data sheet.

Graham

The info about the command byte is a little ambiguous.

However reading more - I noticed that using 080H as the command address is a
*WRITE* command.

You ned to use 081H to read.

All the read 'addresses' are 'odd'. 083H etc....

Graham
 
Sir
I have tried betwn two Aduc's.I have just only transmitted from the
master and no receive process is done.

So the slave should respond to receive the data onlly not to transmit
to master.

This is kept in interrupt polling such as,
when slave receives data from master the i2ci bit set in the I2CCON
register of aduc841.(slave mode)

so in the interrupt routine i have just compliment a port pin to
indicate
that the slave had receive or responded to the master's request.

whether my procedure is correct? or i want to do it in some other
fashion.

slave routine

configur aduc841in slave mode
enable interrupts

wait till interrupt occurs // interrupt occurs when the master
transmits to slave and the slave responds to it.

if (interrupt)
{
cpl port // to indicate the slve's response
}

is this is correct?

regards
alagu.
 
Top