I2C

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
mario1
Posts: 8
Joined: Fri Apr 08, 2011 3:55 am
Has thanked: 18 times
Contact:

I2C

Post 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
Attachments
I2C1.fcf
(7.5 KiB) Downloaded 270 times

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: I2C

Post 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
Attachments
I2C1.fcf
modified example
(7.5 KiB) Downloaded 315 times
the will to learn, should not be stopped by any price

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: I2C

Post by Dan81 »

Hello Mario

have you had a look at this post :

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

Daniel

mario1
Posts: 8
Joined: Fri Apr 08, 2011 3:55 am
Has thanked: 18 times
Contact:

Re: I2C

Post 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

saschech@gmx.de
Posts: 714
Joined: Wed Jan 31, 2007 12:41 pm
Has thanked: 1 time
Been thanked: 26 times
Contact:

Re: I2C

Post 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
Attachments
Slave address.gif
Slave address.gif (58.68 KiB) Viewed 5668 times

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: I2C

Post 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

Post Reply