aqua controller + DS1307 I need some help

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

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

aqua controller + DS1307 I need some help

Postby Jordy101091 » Thu Mar 17, 2011 7:50 pm

Hi everybody,

I have made some real good progress since my last topic I posted here.
I have made a menu where I can set the opperation into different modes and set the temperature levels for HIGH,LOW and NORMAL.

Its all working nice, in the simulation.

But now I whant to add an DS1307 into my project. But I dont now how to start.
I think I need to start with:

Mi2C_Init => MI2C_Start after that I just dont now where to go.

I have read the datasheet over and over but I just dont understand. I have also downloaded some example files but that doesn't work work for me.
The part that confuses is:

when you need to set bits for the clock halt and stuff.
And how to read/write to an adres:

Please can you guys teach me how I'm going to do this.

I really really appreciative it.

Regards Jordy
the will to learn, should not be stopped by any price

User avatar
Benj
Matrix Staff
Posts: 13897
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4179 times
Been thanked: 3957 times
Contact:

Re: aqua controller + DS1307 I need some help

Postby Benj » Fri Mar 18, 2011 11:05 am

Hello Jordy,

Here are example I2C read and write transactions.

Sending Data

Output a start condition //Starts the device listening to the I²C bus.
Transmit the External Device address with the LSB cleared. //Enables the device and sets to write mode.
Transmit the Internal address. //Sets the address to start writing data to.
Transmit a byte of data. //Device will acknowledge and increment internal address until page limit is reached
....
Transmit a byte of data. //Device will acknowledge and increment internal address until page limit is reached
Output a stop condition //Stops the device listening to the I²C bus.

Alternatively use the Send_Byte_Transaction macro.

Note. When writing to a page of memory make sure to only write within that page as if you carry on writing bytes the internal address will wrap around and begin overwriting the first bytes.


Receiving Data

Output a start condition //Starts the device listening to the I²C bus.
Transmit the External Device address with the LSB cleared. //Enables the device and sets to write mode.
Transmit the Internal address. //Sets the address to start reading data from.
Output a restart condition //Restarts the device listening to the I²C bus.
Transmit the External Device address with the LSB set. //Enables the device and sets to read mode.
Receive a byte of data with last byte 0. //Device will send data and increment internal address until page limit is reached
....
Receive a byte of data with last byte 1. //Device will send data.
Output a stop condition //Stops the device listening to the I²C bus.

Alternatively use the Receive_Byte_Transaction macro.

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

Re: aqua controller + DS1307 I need some help

Postby Jordy101091 » Fri Mar 18, 2011 12:50 pm

Hi, Benj

The routine that I need to do, to read and write is now clear to my but what I dont understand are the following things:

Transmit the External Device address with the LSB cleared.


Can you explaine this to me in detail. because I dont now where I can find the External Device address and how do I clear the LSB.

Transmit the Internal address.


How do I do this. When I take a look into the datasheet on page 4 "DS1307 Address Map" I can see that the DS1307 has 8 address 00h / 07h. Therefore can I use the Transmite_Byte Macro, but do I need to fill in 07h ore....

Transmit a byte of data. //Device will acknowledge and increment internal address until page limit is reached


If I want to set the time to be: 00:00:01 do I send an1 as a byte to the 00h address.

Can you help me, thank you
the will to learn, should not be stopped by any price

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: aqua controller + DS1307 I need some help

Postby Spanish_dude » Fri Mar 18, 2011 1:45 pm

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

Jordy101091 wrote:Hi, Benj

The routine that I need to do, to read and write is now clear to my but what I dont understand are the following things:

Transmit the External Device address with the LSB cleared.


Can you explaine this to me in detail. because I dont now where I can find the External Device address and how do I clear the LSB.


You can see the device address in figure 4, 5 and 6 (slave address)

Jordy101091 wrote:
Transmit the Internal address.


How do I do this. When I take a look into the datasheet on page 4 "DS1307 Address Map" I can see that the DS1307 has 8 address 00h / 07h. Therefore can I use the Transmite_Byte Macro, but do I need to fill in 07h ore....


Transmitting the internal address means you just need to send the address of the data you want to write/read.
You'll need to use the Transmit_Byte Macro with the address as argument.

Jordy101091 wrote:
Transmit a byte of data. //Device will acknowledge and increment internal address until page limit is reached


If I want to set the time to be: 00:00:01 do I send an1 as a byte to the 00h address.


Yes you'll need to do that. On reset, the values of the registers are set to : 01/01/00 01 00:00:00 (MM/DD/YY DOW HH:MM:SS)
So, sending a 01h byte to address 00h will set the seconds to 01h.
The CH bit should be kept '0' if you want the oscillator to be enabled.

Regards,

Nicolas L. F.

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

Re: aqua controller + DS1307 I need some help

Postby Jordy101091 » Fri Mar 18, 2011 2:40 pm

Hi, Spanish_dude

Thanks for youre reply.

I have checked the data sheet and it says to me that the device address of the DS1307 is 1101000.

So I have made a little program what I think is right.
Image

But I don't understand how I clear the LSB.

I've used an online calculator to convert the binary 1101000 to an decimal 104 and used that to transmit as the device address.
to write to the internal register and to change the second from 0 to 1 I've don this:

transmit an byte 0 to acces register 00h then => transmit an byte 1 to set the first second. I'm assuming that this is correct if not please explain in detail what I have missed or what I have done wrong
the will to learn, should not be stopped by any price

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: aqua controller + DS1307 I need some help

Postby Spanish_dude » Fri Mar 18, 2011 3:35 pm

To clear the first bit of your byte you can do this like this : "byte = byte & ~(1 << 0)" ( (1 << 0) = 0000 0001b => ~0000 00001b = 1111 1110b)
If "byte" is set to 1111 1111b, then the result would be 1111 1110b

Changing the value '0', from this piece of code ~(1 << 0), to 1 will clear bit 1 of the byte, etc...

Jordy101091 wrote:transmit an byte 0 to acces register 00h then => transmit an byte 1 to set the first second. I'm assuming that this is correct if not please explain in detail what I have missed or what I have done wrong

It is correct as 1(decimal) = 01(hex) = 0000 0001b

Jordy101091 wrote:I have checked the data sheet and it says to me that the device address of the DS1307 is 1101000

This is correct. Don't forget that you need to add the R/W bit with the address so this will look like this: 1101000X (X = 1 for read or 0 for write)

(So your decimal value 104 isn't correct)

Btw, you don't need to convert the binary value into a decimal value. You can write 0b11010000 (bin) or 0xD0 (hex) as argument in the Transmit_Byte macro.

Regards,

Nicolas L. F.
Last edited by Spanish_dude on Fri Mar 18, 2011 5:36 pm, edited 1 time in total.
These users thanked the author Spanish_dude for the post:
Jordy101091 (Fri Mar 18, 2011 5:58 pm)
Rating: 5.88%
 

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

Re: aqua controller + DS1307 I need some help

Postby Jordy101091 » Fri Mar 18, 2011 5:11 pm

Oke,

I think I begin to understand how it all works.

I have grabbed my calculator end set the thing to HEX calculation mode.

So b11010000 is 0xD0 and for b11010001 is 0xD1

so to start the DS1307 to listen to the I2C bus I need to:


1. output an start command
2. Transmit the external device address with the LSB cleared = b11010000 ore 0xD0
3. Transmit the internal address = 0 for seconds
4. Transmit a byte of data = 1 for seconds
5. Wait for an acknowledge
6. output an stop command

When I have done this I have selected address 0 and I have writhed a 1 for one second.
Then I wait for the device to acknowledge the written data.
After that I give an Stop command so the DS1307 stops listening to the BUS.

Is this correct, if not please explain in detail.

Regards Jordy
the will to learn, should not be stopped by any price

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: aqua controller + DS1307 I need some help

Postby Spanish_dude » Fri Mar 18, 2011 5:38 pm

I think that it's correct.

The acknowledge bit is already read by flowcode (I think).

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

Re: aqua controller + DS1307 I need some help

Postby Jordy101091 » Fri Mar 18, 2011 5:58 pm

Oke,

Thanks you very much for your explanation
really appreciate it.

regards Jordy
the will to learn, should not be stopped by any price

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

Re: aqua controller + DS1307 I need some help

Postby Jordy101091 » Fri Mar 18, 2011 6:00 pm

O,

one more thing do I need to hookup the SQW/OUT to my microcontroller.
the will to learn, should not be stopped by any price

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

Re: aqua controller + DS1307 I need some help

Postby Jordy101091 » Sun Mar 20, 2011 12:26 am

Hello,

I have made a little program to write a certain time value into the DS1307

In my program I try to program the time 11:30:00 into the DS1307.

But there are some things going on that I dont understand:

first off all:

This program is based on that from a example file called (init_time_v3.fcf)

first what I have done was: pulled the backup battery out and disconnected the ds1307 from the main power supply, then inserted the battery back in and connected the ds1307 correctly.

Then powered up my EB006 with PIC16F877A and of course with LCD and button eblock. The first thing that happend was:

Random time data was being displayed I thought: press button D0 to right the time data to the DS1307. So after I pussed the button and hold it down. the data 01:01:01 was showing on the display. I dont understand because I programmed 11:30:00.

BUT, when I load the file init_time_v3 into my pic and follow the procedure taking the backup battery......
and connect power again. And then press D0 every thing works fine. except when I whant to reprogram the PIC with another time data. The strange thing happens again. all kinds of time data was showing on the display.

I hope that I'm clear enough.

Hope you can help me, I really want to learn this type of communication.
Attachments
ds1307 test.fcf
(16.5 KiB) Downloaded 315 times
the will to learn, should not be stopped by any price

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: aqua controller + DS1307 I need some help

Postby Spanish_dude » Sun Mar 20, 2011 1:55 pm

Are you using Flowcode v4 ? (I can't open it with my v3)

If you do, you should sing up to that forum and ask your questions there ;).

viewtopic.php?f=29&t=6524
These users thanked the author Spanish_dude for the post:
Benj (Mon Mar 21, 2011 11:34 am)
Rating: 5.88%
 

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

Re: aqua controller + DS1307 I need some help

Postby Jordy101091 » Tue Mar 29, 2011 8:46 pm

Hi, Guys

I have some trouble with my DS1307. I can write the time succesfully but when i'm trying to set the date (dd/mm/yy) I get strange values. I have copy't the calculation from the example file (RTC_4b.fcf) to convert decimal numbers into binary coded decimal numbers.

I use DEC to BCD conversion for setting the time, I thought to use this same formula to convert the date data so the ds1307 can understand it. But one way ore the other it doesn't work. As you can see in the video I have made

What am I doing wrong here, maybe guys from the forum can give me a working example to work with I find out my self what I have done wrong.
I use the eeprom memory to store the converted data that I have set in the menu.

In the video you can see me setting different values of date, but no correct result. Hope you can help me.

AND yes I have selected the wright register address 04H to start writing the date first then the month and last the year and finish with a stop macro.


Link yo video: http://www.vimeo.com/21660419
the will to learn, should not be stopped by any price

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: aqua controller + DS1307 I need some help

Postby Spanish_dude » Tue Mar 29, 2011 9:56 pm

You should post your flowcode file and don't forget to post in the right forum section (Flowcode v4) ;)