Page 1 of 1

I2C

Posted: Tue May 10, 2011 10:24 am
by mario1
Hi
I am new to I2C protocol.Therefore as a starting point I tried to write to a memory location(0x08) in a I2C compatible device (DS1307)and read back the same location and display the value in a Lcd using Flowcode.When I tried to simulate it in Proteus I did not get the value I wrote to the memory location.I have attached the flowcode file below.Any help will be appriciated.

Thanks
Mario1

Re: I2C

Posted: Tue May 10, 2011 4:39 pm
by Jordy101091
Hi Mario,

I have taking a look at you flowcode program,
And what I think is wrong is as follow;

I understand that you are using a DS1307 (RTC)

First thing I found is that you are not giving the DS1307 a read or write command.
If you read the datasheet carefully you will notice that the DS1307 has a slave addres (1101000) http://datasheets.maxim-ic.com/en/ds/DS1307.pdf @ bottom of page 12 (figure 4/5)
Thats when you call the device now the DS1307 needs to be set to write or read mode. this done by a 1 and 0
So you will get this:

1101000 = read mode >>> hexadecimal 0xD0
1101001 = Write mode >>> hexadecimal 0xD1

What I described above is what you need to do after you initialize and start the bus.

Second if you whant to send a byte of data, this part you cant do by just sending 208, 122 or other, you will need to carefully study this page of the datasheet and understand this table @ page 8. You also want to check this page 12 (text not figures).

Tirth if you want to receive information that is stored in the DS1307.
You need to use the receive function. This function works a bit different and I dont now how to explain this properly but I will give it a try.

When you first use a receive function you set the last byte to a 0 because in this case 0 means NO and 1 means YES. The last byte means "is this you final byte to receive". If you want to receive your last byte just put a 1 and after that it stops receiving. hope this helps

I have made A little example for you that you can study and maybe understanding the I2C protocol a little bit more (hope it works :))

Regards Jordy

PS If you need help let me know

Re: I2C

Posted: Tue May 10, 2011 5:30 pm
by Dan81
Hello Mario

have you had a look at this post :

http://www.matrixmultimedia.com/mmforum ... rtc#p13533

Daniel

Re: I2C

Posted: Wed May 11, 2011 7:07 am
by mario1
Hi Jordy
Thanks for the quick reply and instructions.I studied your modified file and I am a little bit confused how you addressed the internal memory location address of DS1307.(Not the slave address 1101000).Can you please explain.

Once again thanks

Mario

Re: I2C

Posted: Wed May 11, 2011 8:03 am
by saschech@gmx.de
Hello Mario

have a look to the datasheet....

With the rw bit 1101 000_1 = 0xd1

http://datasheets.maxim-ic.com/en/ds/DS1307.pdf

regards wolfgang

Re: I2C

Posted: Wed May 11, 2011 11:38 am
by Dan81
Hello Mario

If you want to write (or read) the memory (RAM), it is the same thing as writing (or reading) the RTC registers. Only the value of the register is different.
The 8 first bytes are RTC registers and the 56 others are RAM registers.
The slave adress is always 0xD0 (write) or 0xD1 (read).

The RTC registers are BCD coded, you must do some calculations before displaying them.

Daniel